Browse Source

WIP: #243 coudn't display page contents

Yuki Takei 8 years ago
parent
commit
8c6d85ae1a
2 changed files with 12 additions and 8 deletions
  1. 6 7
      resource/js/components/PageEditor.js
  2. 6 1
      resource/js/legacy/crowi.js

+ 6 - 7
resource/js/components/PageEditor.js

@@ -39,16 +39,13 @@ export default class PageEditor extends React.Component {
     // create throttled function
     // create throttled function
     this.renderWithDebounce = debounce(50, throttle(100, this.renderPreview));
     this.renderWithDebounce = debounce(50, throttle(100, this.renderPreview));
     this.saveDraftWithDebounce = debounce(300, this.saveDraft);
     this.saveDraftWithDebounce = debounce(300, this.saveDraft);
-
-    // initial rendering
-    this.renderPreview(this.state.markdown);
   }
   }
 
 
   componentWillMount() {
   componentWillMount() {
     // restore draft
     // restore draft
     this.restoreDraft();
     this.restoreDraft();
-    // initial preview
-    this.renderPreview();
+    // initial rendering
+    this.renderPreview(this.state.markdown);
   }
   }
 
 
   focusToEditor() {
   focusToEditor() {
@@ -233,6 +230,8 @@ export default class PageEditor extends React.Component {
   renderPreview(value) {
   renderPreview(value) {
     const config = this.props.crowi.config;
     const config = this.props.crowi.config;
 
 
+    this.setState({ markdown: value });
+
     // generate options obj
     // generate options obj
     const rendererOptions = {
     const rendererOptions = {
       // see: https://www.npmjs.com/package/marked
       // see: https://www.npmjs.com/package/marked
@@ -243,7 +242,7 @@ export default class PageEditor extends React.Component {
 
 
     // render html
     // render html
     var context = {
     var context = {
-      markdown: value,
+      markdown: this.state.markdown,
       dom: this.previewElement,
       dom: this.previewElement,
       currentPagePath: decodeURIComponent(location.pathname)
       currentPagePath: decodeURIComponent(location.pathname)
     };
     };
@@ -262,7 +261,7 @@ export default class PageEditor extends React.Component {
       .then(() => crowi.interceptorManager.process('preRenderPreviewHtml', context))
       .then(() => crowi.interceptorManager.process('preRenderPreviewHtml', context))
       .then(() => {
       .then(() => {
         this.setState({
         this.setState({
-          markdown: value,
+          markdown: context.markdown,
           html: context.parsedHTML,
           html: context.parsedHTML,
         });
         });
 
 

+ 6 - 1
resource/js/legacy/crowi.js

@@ -457,7 +457,12 @@ $(function() {
     var $link = $(this);
     var $link = $(this);
     var text = $link.text();
     var text = $link.text();
     var path = $link.data('path');
     var path = $link.data('path');
-    var shortPath = new String($link.data('short-path'));
+    var shortPath = String($link.data('short-path'));
+
+    if (path == null || shortPath == null) {
+      // continue
+      return;
+    }
 
 
     var escape = function(s) {
     var escape = function(s) {
       return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
       return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');