fix: front-matter 解析错误容错

This commit is contained in:
purocean
2021-11-03 19:26:04 +08:00
parent a81b3bd11d
commit b30f5f2cc7
+15 -4
View File
@@ -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<string, any> = {}
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 })
}