Skip to content

Commit 6c929a1

Browse files
author
wangyongqing01
committed
fix: 判断```html 中的代码是不是严格意义的 san 组件代码
1 parent c07bc41 commit 6c929a1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const getText = require('./utils/getText').getText;
1515

1616
const EXPORT_TYPES = ['app', 'component', 'object', 'md', 'markdown'];
1717

18-
function getMarkdownDefaultSanCode(content, cls) {
19-
cls = cls || ['markdown'];
18+
function getMarkdownDefaultSanCode(content, cls = ['markdown']) {
2019
if (!Array.isArray(cls)) {
2120
cls = cls.split(/\s+/);
2221
}
@@ -147,14 +146,17 @@ export default ${JSON.stringify(data).replace(/(['"])sanComponent\1/g, 'sanCompo
147146
function genAppComponent(template, {text, code, content}) {
148147
const {resourcePath} = this;
149148
// getsource
150-
if (!code) {
149+
// 这里判断下是否是严格意义上的 san 组件
150+
// 1. 存在 template tag,并且肯定不是一上来就闭合吧
151+
if (!code || code.indexOf('</template>')) {
151152
// 说明是纯 markdown
152153
return getMarkdownDefaultSanCode(compiler(content));
153154
}
154155

155156
const textHtml = text ? compiler(text) : text;
156157
// 解决文档中的语法被解析的问题
157158
let codeHtml = `<pre><code class="language-html">${code.replace(/</g, '&lt;').replace(/`/g, '\\`')}</code></pre>`;
159+
158160
const requirePath = getComponentImportFromCode(resourcePath, content);
159161

160162
let id = 'components-demo-' + Date.now();

0 commit comments

Comments
 (0)