From 8b1000a4a55532419d8f8e41b797c15e2a5442cc Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Wed, 4 Jan 2017 21:41:08 +0800 Subject: [PATCH] feat: Markdown parser is configurable, #42 --- src/render.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/render.js b/src/render.js index 13312127d..63d1937f8 100644 --- a/src/render.js +++ b/src/render.js @@ -5,6 +5,7 @@ import { activeLink, scrollActiveSidebar, bindToggle, scroll2Top, sticky } from import { genTree, getRoute, isMobile, slugify, merge } from './util' let OPTIONS = {} +let markdown = marked let toc = [] const CACHE = {} @@ -54,7 +55,13 @@ export function init (options) { return `${text}` } - marked.setOptions(merge({ renderer }, OPTIONS.marked)) + + if (typeof OPTIONS.markdown === 'function') { + markdown.setOptions({ renderer }) + markdown = OPTIONS.markdown.call(this, markdown) + } else { + markdown.setOptions(merge({ renderer }, OPTIONS.markdown)) + } } /** @@ -84,7 +91,7 @@ export function renderApp (dom, replace) { * article */ export function renderArticle (content) { - renderTo('article', content ? marked(content) : 'not found') + renderTo('article', content ? markdown(content) : 'not found') if (!OPTIONS.sidebar && !OPTIONS.loadSidebar) renderSidebar() if (content && typeof Vue !== 'undefined' && typeof Vuep !== 'undefined') { @@ -101,7 +108,7 @@ export function renderNavbar (content) { if (CACHE.navbar && CACHE.navbar === content) return CACHE.navbar = content - if (content) renderTo('nav', marked(content)) + if (content) renderTo('nav', markdown(content)) activeLink('nav') } @@ -112,7 +119,7 @@ export function renderSidebar (content) { let html if (content) { - html = marked(content) + html = markdown(content) } else if (OPTIONS.sidebar) { html = tpl.tree(OPTIONS.sidebar, '