@@ -11,82 +11,81 @@ import { Compiler } from './compiler';
11
11
import * as tpl from './tpl' ;
12
12
import { prerenderEmbed } from './embed' ;
13
13
14
- function executeScript ( ) {
15
- const script = dom
16
- . findAll ( '.markdown-section>script' )
17
- . filter ( s => ! / t e m p l a t e / . test ( s . type ) ) [ 0 ] ;
18
- if ( ! script ) {
19
- return false ;
20
- }
21
-
22
- const code = script . innerText . trim ( ) ;
23
- if ( ! code ) {
24
- return false ;
25
- }
26
-
27
- setTimeout ( _ => {
28
- window . __EXECUTE_RESULT__ = new Function ( code ) ( ) ;
29
- } , 0 ) ;
30
- }
14
+ export function renderMixin ( Base = class { } ) {
15
+ return class extends Base {
16
+ _executeScript ( ) {
17
+ const script = dom
18
+ . findAll ( '.markdown-section>script' )
19
+ . filter ( s => ! / t e m p l a t e / . test ( s . type ) ) [ 0 ] ;
20
+ if ( ! script ) {
21
+ return false ;
22
+ }
31
23
32
- function formatUpdated ( html , updated , fn ) {
33
- updated =
34
- typeof fn === 'function'
35
- ? fn ( updated )
36
- : typeof fn === 'string'
37
- ? tinydate ( fn ) ( new Date ( updated ) )
38
- : updated ;
24
+ const code = script . innerText . trim ( ) ;
25
+ if ( ! code ) {
26
+ return false ;
27
+ }
39
28
40
- return html . replace ( / { d o c s i f y - u p d a t e d } / g, updated ) ;
41
- }
29
+ setTimeout ( _ => {
30
+ window . __EXECUTE_RESULT__ = new Function ( code ) ( ) ;
31
+ } , 0 ) ;
32
+ }
42
33
43
- function renderMain ( html ) {
44
- if ( ! html ) {
45
- html = '<h1>404 - Not found</h1>' ;
46
- }
47
-
48
- this . _renderTo ( '.markdown-section' , html ) ;
49
- // Render sidebar with the TOC
50
- ! this . config . loadSidebar && this . _renderSidebar ( ) ;
51
-
52
- // Execute script
53
- if (
54
- this . config . executeScript !== false &&
55
- typeof window . Vue !== 'undefined' &&
56
- ! executeScript ( )
57
- ) {
58
- setTimeout ( _ => {
59
- const vueVM = window . __EXECUTE_RESULT__ ;
60
- vueVM && vueVM . $destroy && vueVM . $destroy ( ) ;
61
- window . __EXECUTE_RESULT__ = new window . Vue ( ) . $mount ( '#main' ) ;
62
- } , 0 ) ;
63
- } else {
64
- this . config . executeScript && executeScript ( ) ;
65
- }
66
- }
34
+ _formatUpdated ( html , updated , fn ) {
35
+ updated =
36
+ typeof fn === 'function'
37
+ ? fn ( updated )
38
+ : typeof fn === 'string'
39
+ ? tinydate ( fn ) ( new Date ( updated ) )
40
+ : updated ;
41
+
42
+ return html . replace ( / { d o c s i f y - u p d a t e d } / g, updated ) ;
43
+ }
44
+
45
+ __renderMain ( html ) {
46
+ if ( ! html ) {
47
+ html = '<h1>404 - Not found</h1>' ;
48
+ }
67
49
68
- function renderNameLink ( vm ) {
69
- const el = dom . getNode ( '.app-name-link' ) ;
70
- const nameLink = vm . config . nameLink ;
71
- const path = vm . route . path ;
50
+ this . _renderTo ( '.markdown-section' , html ) ;
51
+ // Render sidebar with the TOC
52
+ ! this . config . loadSidebar && this . _renderSidebar ( ) ;
53
+
54
+ // Execute script
55
+ if (
56
+ this . config . executeScript !== false &&
57
+ typeof window . Vue !== 'undefined' &&
58
+ ! this . _executeScript ( )
59
+ ) {
60
+ setTimeout ( _ => {
61
+ const vueVM = window . __EXECUTE_RESULT__ ;
62
+ vueVM && vueVM . $destroy && vueVM . $destroy ( ) ;
63
+ window . __EXECUTE_RESULT__ = new window . Vue ( ) . $mount ( '#main' ) ;
64
+ } , 0 ) ;
65
+ } else {
66
+ this . config . executeScript && this . _executeScript ( ) ;
67
+ }
68
+ }
72
69
73
- if ( ! el ) {
74
- return ;
75
- }
70
+ _renderNameLink ( vm ) {
71
+ const el = dom . getNode ( '.app-name-link' ) ;
72
+ const nameLink = vm . config . nameLink ;
73
+ const path = vm . route . path ;
76
74
77
- if ( isPrimitive ( vm . config . nameLink ) ) {
78
- el . setAttribute ( 'href' , nameLink ) ;
79
- } else if ( typeof nameLink === 'object' ) {
80
- const match = Object . keys ( nameLink ) . filter (
81
- key => path . indexOf ( key ) > - 1
82
- ) [ 0 ] ;
75
+ if ( ! el ) {
76
+ return ;
77
+ }
83
78
84
- el . setAttribute ( 'href' , nameLink [ match ] ) ;
85
- }
86
- }
79
+ if ( isPrimitive ( vm . config . nameLink ) ) {
80
+ el . setAttribute ( 'href' , nameLink ) ;
81
+ } else if ( typeof nameLink === 'object' ) {
82
+ const match = Object . keys ( nameLink ) . filter (
83
+ key => path . indexOf ( key ) > - 1
84
+ ) [ 0 ] ;
87
85
88
- export function renderMixin ( Base = class { } ) {
89
- return class extends Base {
86
+ el . setAttribute ( 'href' , nameLink [ match ] ) ;
87
+ }
88
+ }
90
89
_renderTo ( el , content , replace ) {
91
90
const node = dom . getNode ( el ) ;
92
91
if ( node ) {
@@ -147,21 +146,21 @@ export function renderMixin(Base = class {}) {
147
146
148
147
_renderMain ( text , opt = { } , next ) {
149
148
if ( ! text ) {
150
- return renderMain . call ( this , text ) ;
149
+ return this . __renderMain ( text ) ;
151
150
}
152
151
153
152
this . callHook ( 'beforeEach' , text , result => {
154
153
let html ;
155
154
const callback = ( ) => {
156
155
if ( opt . updatedAt ) {
157
- html = formatUpdated (
156
+ html = this . _formatUpdated (
158
157
html ,
159
158
opt . updatedAt ,
160
159
this . config . formatUpdated
161
160
) ;
162
161
}
163
162
164
- this . callHook ( 'afterEach' , html , text => renderMain . call ( this , text ) ) ;
163
+ this . callHook ( 'afterEach' , html , text => this . __renderMain ( text ) ) ;
165
164
} ;
166
165
167
166
if ( this . isHTML ) {
@@ -230,7 +229,7 @@ export function renderMixin(Base = class {}) {
230
229
231
230
_render_updateRender ( ) {
232
231
// Render name link
233
- renderNameLink ( this ) ;
232
+ this . _renderNameLink ( this ) ;
234
233
}
235
234
236
235
initRender ( ) {
0 commit comments