Skip to content

Commit 8b1000a

Browse files
committedJan 4, 2017
feat: Markdown parser is configurable, #42
1 parent 8972834 commit 8b1000a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed
 

‎src/render.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { activeLink, scrollActiveSidebar, bindToggle, scroll2Top, sticky } from
55
import { genTree, getRoute, isMobile, slugify, merge } from './util'
66

77
let OPTIONS = {}
8+
let markdown = marked
89
let toc = []
910
const CACHE = {}
1011

@@ -54,7 +55,13 @@ export function init (options) {
5455

5556
return `<a href="${href}" title="${title || ''}">${text}</a>`
5657
}
57-
marked.setOptions(merge({ renderer }, OPTIONS.marked))
58+
59+
if (typeof OPTIONS.markdown === 'function') {
60+
markdown.setOptions({ renderer })
61+
markdown = OPTIONS.markdown.call(this, markdown)
62+
} else {
63+
markdown.setOptions(merge({ renderer }, OPTIONS.markdown))
64+
}
5865
}
5966

6067
/**
@@ -84,7 +91,7 @@ export function renderApp (dom, replace) {
8491
* article
8592
*/
8693
export function renderArticle (content) {
87-
renderTo('article', content ? marked(content) : 'not found')
94+
renderTo('article', content ? markdown(content) : 'not found')
8895
if (!OPTIONS.sidebar && !OPTIONS.loadSidebar) renderSidebar()
8996

9097
if (content && typeof Vue !== 'undefined' && typeof Vuep !== 'undefined') {
@@ -101,7 +108,7 @@ export function renderNavbar (content) {
101108
if (CACHE.navbar && CACHE.navbar === content) return
102109
CACHE.navbar = content
103110

104-
if (content) renderTo('nav', marked(content))
111+
if (content) renderTo('nav', markdown(content))
105112
activeLink('nav')
106113
}
107114

@@ -112,7 +119,7 @@ export function renderSidebar (content) {
112119
let html
113120

114121
if (content) {
115-
html = marked(content)
122+
html = markdown(content)
116123
} else if (OPTIONS.sidebar) {
117124
html = tpl.tree(OPTIONS.sidebar, '<ul>')
118125
} else {
@@ -145,7 +152,7 @@ export function renderCover (content) {
145152
if (renderCover.rendered) return
146153

147154
// render cover
148-
let html = marked(content)
155+
let html = markdown(content)
149156
const match = html.trim().match('<p><img[^s]+src="(.*?)"[^a]+alt="(.*?)"></p>$')
150157

151158
// render background

0 commit comments

Comments
 (0)