From 03eab0b2a6f75eee442d39aec1583ad63bf7769c Mon Sep 17 00:00:00 2001 From: chenzhangxiang Date: Fri, 14 Jan 2022 21:03:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(./src/common/containers.js):=20=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E5=BC=95=E5=85=A5=E4=BB=A3=E7=A0=81=E6=AE=B5=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E7=A1=AE=E6=B8=B2=E6=9F=93=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #14 --- src/common/containers.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/common/containers.js b/src/common/containers.js index 9732088..2e5d04b 100644 --- a/src/common/containers.js +++ b/src/common/containers.js @@ -1,5 +1,5 @@ +const fs = require('fs'); const mdContainer = require('markdown-it-container'); - module.exports = options => { const { component = 'demo-block' @@ -16,7 +16,15 @@ module.exports = options => { const m = tokens[idx].info.trim().match(/^demo\s*(.*)$/); if (tokens[idx].nesting === 1) { const description = m && m.length > 1 ? m[1] : ''; - const content = tokens[idx + 1].type === 'fence' ? tokens[idx + 1].content : ''; + let content = '' + if (tokens[idx + 1].type === 'fence') { + if (tokens[idx + 1].content) { + content = tokens[idx + 1].content + } else if (tokens[idx + 1].src) { + // 根据路径加载文件 + content = fs.readFileSync(tokens[idx + 1].src, 'utf-8') + } + } const encodeOptionsStr = encodeURI(JSON.stringify(options)); return `<${componentName} :options="JSON.parse(decodeURI('${encodeOptionsStr}'))">