@@ -6,6 +6,7 @@ import hljs from 'highlight.js';
6
6
import styles from './style/index.less' ;
7
7
import InlineCode from './InlineCode' ;
8
8
import Link from './Link' ;
9
+ import Loading from '../../component/Loading/' ;
9
10
10
11
hljs . configure ( {
11
12
tabReplace : ' ' , // 2 spaces
@@ -23,7 +24,7 @@ export default class Markdown extends React.Component {
23
24
constructor ( props ) {
24
25
super ( props ) ;
25
26
this . state = {
26
- markdownStr : 'loading ... ' ,
27
+ markdownStr : '' ,
27
28
} ;
28
29
}
29
30
componentWillMount ( ) {
@@ -53,36 +54,41 @@ export default class Markdown extends React.Component {
53
54
}
54
55
render ( ) {
55
56
const { mdconf : { title, layout } } = this . props ;
57
+ const { markdownStr } = this . state ;
56
58
return (
57
59
< div className = { styles . markdownWapper } >
58
60
{ title && layout !== 'IndexLayout' && < h1 id = { title } className = { styles . pageTitle } > { title } </ h1 > }
59
- < ReactMarkdown
60
- className = { classNames ( 'markdown' , styles . markdown ) }
61
- source = { this . state . markdownStr }
62
- escapeHtml = { false }
63
- renderers = { {
64
- code : InlineCode ,
65
- link : Link ,
66
- linkReference : Link ,
67
- } }
68
- allowNode = { ( node , index , parent ) => {
69
- if ( node . type === 'html' ) {
70
- // if (/<!--([^]+?)-->/.test(node.value)) return false;
71
- // const scriptValue = node.value.match(/<script.*?>(.*?)<\/script>/ig);
72
- // node.value.replace(/<script.*?>(.*?)<\/script>/, (te) => {
73
- // console.log('te:', te);
74
- // });
75
- }
76
- // 判断 上一个节点是否为 <!--DemoStart -->
77
- if ( node . type === 'code' && parent . children && parent . children . length > 0 && parent . children [ index - 1 ] ) {
78
- const parentNode = parent . children [ index - 1 ] ;
79
- if ( parentNode . type === 'html' && / < ! - - \s ? D e m o S t a r t \s ? - - > / . test ( parentNode . value ) ) {
80
- node . value = `__dome__${ node . value } ` ;
61
+ { markdownStr ? (
62
+ < ReactMarkdown
63
+ className = { classNames ( 'markdown' , styles . markdown ) }
64
+ source = { markdownStr }
65
+ escapeHtml = { false }
66
+ renderers = { {
67
+ code : InlineCode ,
68
+ link : Link ,
69
+ linkReference : Link ,
70
+ } }
71
+ allowNode = { ( node , index , parent ) => {
72
+ if ( node . type === 'html' ) {
73
+ // if (/<!--([^]+?)-->/.test(node.value)) return false;
74
+ // const scriptValue = node.value.match(/<script.*?>(.*?)<\/script>/ig);
75
+ // node.value.replace(/<script.*?>(.*?)<\/script>/, (te) => {
76
+ // console.log('te:', te);
77
+ // });
81
78
}
82
- }
83
- return node ;
84
- } }
85
- />
79
+ // 判断 上一个节点是否为 <!--DemoStart -->
80
+ if ( node . type === 'code' && parent . children && parent . children . length > 0 && parent . children [ index - 1 ] ) {
81
+ const parentNode = parent . children [ index - 1 ] ;
82
+ if ( parentNode . type === 'html' && / < ! - - \s ? D e m o S t a r t \s ? - - > / . test ( parentNode . value ) ) {
83
+ node . value = `__dome__${ node . value } ` ;
84
+ }
85
+ }
86
+ return node ;
87
+ } }
88
+ />
89
+ ) : (
90
+ < Loading />
91
+ ) }
86
92
</ div >
87
93
) ;
88
94
}
0 commit comments