@@ -9,6 +9,8 @@ import { isFn, merge, cached } from '../util/core'
9
9
import { get } from '../fetch/ajax'
10
10
11
11
const cachedLinks = { }
12
+ let uid = 0
13
+
12
14
function getAndRemoveConfig ( str = '' ) {
13
15
const config = { }
14
16
@@ -25,14 +27,23 @@ function getAndRemoveConfig (str = '') {
25
27
}
26
28
const compileMedia = {
27
29
markdown ( url , config ) {
28
- const request = get ( url , false )
29
- const id = `docsify-get-${ request . uid } `
30
+ const id = `docsify-get-${ uid ++ } `
30
31
31
- request . then ( text => {
32
- document . getElementById ( id ) . innerHTML = this . compile ( text )
33
- } )
32
+ if ( ! process . env . SSR ) {
33
+ get ( url , false ) . then ( text => {
34
+ document . getElementById ( id ) . innerHTML = this . compile ( text )
35
+ } )
34
36
35
- return `<div data-origin="${ url } " id=${ id } ></div>`
37
+ return `<div data-origin="${ url } " id=${ id } ></div>`
38
+ } else {
39
+ return `<div data-origin="${ url } " id=${ uid } ></div>
40
+ <script>
41
+ var compile = window.__current_docsify_compiler__
42
+ Docsify.get('${ url } ', false).then(function(text) {
43
+ document.getElementById('${ uid } ').innerHTML = compile(text)
44
+ })
45
+ </script>`
46
+ }
36
47
} ,
37
48
html ( url , config ) {
38
49
return `<iframe src="${ url } " ${ config || 'width=100% height=400' } ></iframe>`
@@ -44,19 +55,33 @@ const compileMedia = {
44
55
return `<audio src="${ url } " ${ config || 'controls' } >Not Support</audio>`
45
56
} ,
46
57
code ( url , config ) {
47
- const request = get ( url , false )
48
- const id = `docsify-get-${ request . uid } `
58
+ const id = `docsify-get-${ uid ++ } `
49
59
let ext = url . match ( / \. ( \w + ) $ / )
50
60
51
- ext = config . ext || ( ext && ext [ 0 ] )
61
+ ext = config . ext || ( ext && ext [ 1 ] )
62
+ if ( ext === 'md' ) ext = 'markdown'
52
63
53
- request . then ( text => {
54
- document . getElementById ( id ) . innerHTML = this . compile (
55
- '```' + ext + '\n ' + text + '\n```\n'
56
- )
57
- } )
64
+ if ( ! process . env . SSR ) {
65
+ get ( url , false ) . then ( text => {
66
+ document . getElementById ( id ) . innerHTML = this . compile (
67
+ '```' + ext + '\n' + text . replace ( / ` / g, '@qm@' ) + '\n```\n'
68
+ ) . replace ( / @ q m @ / g, '`' )
69
+ } )
58
70
59
- return `<div data-origin="${ url } " id=${ id } ></div>`
71
+ return `<div data-origin="${ url } " id=${ id } ></div>`
72
+ } else {
73
+ return `<div data-origin="${ url } " id=${ id } ></div>
74
+ <script>
75
+ setTimeout(() => {
76
+ var compiler = window.__current_docsify_compiler__
77
+ Docsify.get('${ url } ', false).then(function(text) {
78
+ document.getElementById('${ id } ').innerHTML = compiler
79
+ .compile('\`\`\`${ ext } \\n' + text.replace(/\`/g, '@qm@') + '\\n\`\`\`\\n')
80
+ .replace(/@qm@/g, '\`')
81
+ })
82
+ })
83
+ </script>`
84
+ }
60
85
}
61
86
}
62
87
0 commit comments