From b30f5f2cc7d876607c0377d09781a4e95808cb54 Mon Sep 17 00:00:00 2001 From: purocean Date: Wed, 3 Nov 2021 19:26:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20front-matter=20=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=AE=B9=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/plugins/markdown-front-matter.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/renderer/plugins/markdown-front-matter.ts b/src/renderer/plugins/markdown-front-matter.ts index 5daa8e48..d8f82fbd 100644 --- a/src/renderer/plugins/markdown-front-matter.ts +++ b/src/renderer/plugins/markdown-front-matter.ts @@ -7,13 +7,24 @@ export default { const logger = ctx.utils.getLogger('markdown-front-matter') ctx.markdown.registerPlugin(md => { const render = md.render + md.render = (src: string, env?: any) => { - const fm = frontMatter(src) - const bodyBegin = fm.bodyBegin - 1 - const attributes = typeof fm.attributes === 'object' ? fm.attributes : {} + let bodyBegin = 0 + let attributes: Record = {} + try { + const fm = frontMatter(src) + + bodyBegin = fm.bodyBegin - 1 + if (fm.attributes && typeof fm.attributes === 'object') { + attributes = fm.attributes + } + + return render.call(md, src, { ...env, bodyBegin, attributes }) + } catch (error) { + console.error(error) + } logger.debug('render', bodyBegin, attributes) - return render.call(md, src, { ...env, bodyBegin, attributes }) }