@@ -2,9 +2,9 @@ import marked from 'marked'
2
2
import Prism from 'prismjs'
3
3
import * as tpl from './tpl'
4
4
import * as event from './event'
5
+ import * as polyfill from './polyfill'
5
6
import { genTree , getRoute , isMobile , slugify , merge , emojify } from './util'
6
7
7
- let OPTIONS = { }
8
8
let markdown = marked
9
9
let toc = [ ]
10
10
const CACHE = { }
@@ -19,11 +19,8 @@ const renderTo = function (dom, content) {
19
19
20
20
/**
21
21
* init render
22
- * @param {Object } options
23
22
*/
24
- export function init ( options ) {
25
- OPTIONS = options
26
-
23
+ export function init ( ) {
27
24
const renderer = new marked . Renderer ( )
28
25
/**
29
26
* render anchor tag
@@ -33,7 +30,7 @@ export function init (options) {
33
30
const slug = slugify ( text )
34
31
let route = ''
35
32
36
- if ( OPTIONS . router ) {
33
+ if ( __docsify__ . router ) {
37
34
route = `#/${ getRoute ( ) } `
38
35
}
39
36
@@ -48,7 +45,7 @@ export function init (options) {
48
45
return `<pre v-pre data-lang="${ lang } "><code class="lang-${ lang } ">${ hl . replace ( / : / g, '__colon__' ) } </code></pre>`
49
46
}
50
47
renderer . link = function ( href , title , text ) {
51
- if ( OPTIONS . router && ! / : / . test ( href ) ) {
48
+ if ( __docsify__ . router && ! / : / . test ( href ) ) {
52
49
href = `#/${ href } ` . replace ( / \/ \/ / g, '/' )
53
50
}
54
51
@@ -63,11 +60,11 @@ export function init (options) {
63
60
return `<p>${ text } </p>`
64
61
}
65
62
66
- if ( typeof OPTIONS . markdown === 'function' ) {
63
+ if ( typeof __docsify__ . markdown === 'function' ) {
67
64
markdown . setOptions ( { renderer } )
68
- markdown = OPTIONS . markdown . call ( this , markdown )
65
+ markdown = __docsify__ . markdown . call ( this , markdown )
69
66
} else {
70
- markdown . setOptions ( merge ( { renderer } , OPTIONS . markdown ) )
67
+ markdown . setOptions ( merge ( { renderer } , __docsify__ . markdown ) )
71
68
}
72
69
73
70
const md = markdown
@@ -81,17 +78,23 @@ export function init (options) {
81
78
export function renderApp ( dom , replace ) {
82
79
const nav = document . querySelector ( 'nav' ) || document . createElement ( 'nav' )
83
80
84
- if ( ! OPTIONS . repo ) nav . classList . add ( 'no-badge' )
81
+ if ( ! __docsify__ . repo ) nav . classList . add ( 'no-badge' )
85
82
86
- dom [ replace ? 'outerHTML' : 'innerHTML' ] = tpl . corner ( OPTIONS . repo ) +
87
- ( OPTIONS . coverpage ? tpl . cover ( ) : '' ) +
88
- tpl . main ( OPTIONS . sidebarToggle ? tpl . toggle ( ) : '' )
83
+ dom [ replace ? 'outerHTML' : 'innerHTML' ] = tpl . corner ( __docsify__ . repo ) +
84
+ ( __docsify__ . coverpage ? tpl . cover ( ) : '' ) +
85
+ tpl . main ( __docsify__ . sidebarToggle ? tpl . toggle ( ) : '' )
89
86
document . body . insertBefore ( nav , document . body . children [ 0 ] )
90
87
88
+ // theme color
89
+ if ( __docsify__ . themeColor ) {
90
+ document . head . innerHTML += tpl . theme ( __docsify__ . themeColor )
91
+ polyfill . cssVars ( )
92
+ }
93
+
91
94
// bind toggle
92
95
event . bindToggle ( 'button.sidebar-toggle' )
93
96
// bind sticky effect
94
- if ( OPTIONS . coverpage ) {
97
+ if ( __docsify__ . coverpage ) {
95
98
! isMobile ( ) && window . addEventListener ( 'scroll' , event . sticky )
96
99
} else {
97
100
document . body . classList . add ( 'sticky' )
@@ -103,7 +106,7 @@ export function renderApp (dom, replace) {
103
106
*/
104
107
export function renderArticle ( content ) {
105
108
renderTo ( 'article' , content ? markdown ( content ) : 'not found' )
106
- if ( ! OPTIONS . sidebar && ! OPTIONS . loadSidebar ) renderSidebar ( )
109
+ if ( ! __docsify__ . sidebar && ! __docsify__ . loadSidebar ) renderSidebar ( )
107
110
108
111
if ( content && typeof Vue !== 'undefined' ) {
109
112
CACHE . vm && CACHE . vm . $destroy ( )
@@ -120,7 +123,7 @@ export function renderArticle (content) {
120
123
: new Vue ( { el : 'main' } ) // eslint-disable-line
121
124
CACHE . vm && CACHE . vm . $nextTick ( _ => event . scrollActiveSidebar ( ) )
122
125
}
123
- if ( OPTIONS . auto2top ) setTimeout ( ( ) => event . scroll2Top ( OPTIONS . auto2top ) , 0 )
126
+ if ( __docsify__ . auto2top ) setTimeout ( ( ) => event . scroll2Top ( __docsify__ . auto2top ) , 0 )
124
127
}
125
128
126
129
/**
@@ -144,13 +147,13 @@ export function renderSidebar (content) {
144
147
html = markdown ( content )
145
148
// find url tag
146
149
html = html . match ( / < u l [ ^ > ] * > ( [ \s \S ] + ) < \/ u l > / g) [ 0 ]
147
- } else if ( OPTIONS . sidebar ) {
148
- html = tpl . tree ( OPTIONS . sidebar , '<ul>' )
150
+ } else if ( __docsify__ . sidebar ) {
151
+ html = tpl . tree ( __docsify__ . sidebar , '<ul>' )
149
152
} else {
150
- html = tpl . tree ( genTree ( toc , OPTIONS . maxLevel ) , '<ul>' )
153
+ html = tpl . tree ( genTree ( toc , __docsify__ . maxLevel ) , '<ul>' )
151
154
}
152
155
153
- html = ( OPTIONS . name ? `<h1><a href="${ OPTIONS . nameLink } ">${ OPTIONS . name } </a></h1>` : '' ) + html
156
+ html = ( __docsify__ . name ? `<h1><a href="${ __docsify__ . nameLink } ">${ __docsify__ . name } </a></h1>` : '' ) + html
154
157
renderTo ( 'aside.sidebar' , html )
155
158
const target = event . activeLink ( 'aside.sidebar' , true )
156
159
if ( target ) renderSubSidebar ( target )
@@ -160,8 +163,8 @@ export function renderSidebar (content) {
160
163
}
161
164
162
165
export function renderSubSidebar ( target ) {
163
- if ( ! OPTIONS . subMaxLevel ) return
164
- target . parentNode . innerHTML += tpl . tree ( genTree ( toc , OPTIONS . subMaxLevel ) , '<ul>' )
166
+ if ( ! __docsify__ . subMaxLevel ) return
167
+ target . parentNode . innerHTML += tpl . tree ( genTree ( toc , __docsify__ . subMaxLevel ) , '<ul>' )
165
168
}
166
169
167
170
/**
0 commit comments