doc: update md plugin

This commit is contained in:
tangjinzhou 2021-11-26 17:17:40 +08:00
parent b07882d92f
commit 3a141b2e9b
8 changed files with 14 additions and 12 deletions

View File

@ -13,7 +13,6 @@ title:
## en-US
Read only, can't use mouse to interact.
</docs>
<template>
<a-rate :value="2" disabled />

View File

@ -19,10 +19,10 @@ Using this component, you can smoothly scroll through 100,000 rows and 100,000 c
</docs>
<template>
<iframe src="https://www.surely.cool/for-ant-demo" height="400" />
<iframe src="https://www.surely.cool/for-ant-demo" height="400"></iframe>
<div v-if="false">
you can visit
<a href="https://www.surely.cool" />
<a href="https://www.surely.cool"></a>
get more info
</div>
</template>

View File

@ -30,7 +30,7 @@ function createContainer(klass: string, defaultTitle: string): ContainerArgs {
{
render(tokens, idx) {
const token = tokens[idx];
const info = token.info.trim().slice(klass.length)?.trim();
const info = token.info?.trim().slice(klass.length)?.trim();
if (token.nesting === 1) {
return `<div class="${klass} custom-block"><p class="custom-block-title">${
info || defaultTitle

View File

@ -7,7 +7,7 @@ export const hoistPlugin = (md: MarkdownIt) => {
const RE = /^<(script|style)(?=(\s|>|$))/i;
md.renderer.rules.html_block = (tokens, idx) => {
const content = tokens[idx].content;
const content = tokens[idx].content || '';
const data = (md as any).__data as MarkdownParsedData;
const hoistedTags = data.hoistedTags || (data.hoistedTags = []);
if (RE.test(content.trim())) {

View File

@ -16,10 +16,13 @@ export const preWrapperPlugin = (md: MarkdownIt) => {
const [tokens, idx] = args;
const token = tokens[idx];
const data = (md as any).__data as MarkdownParsedData;
if (token.info.trim() === 'vue') {
if (token.info?.trim() === 'vue') {
data.vueCode = token.content;
}
const rawCode = fence(...args).replace(/<pre /g, `<pre class="language-${token.info.trim()}" `);
const rawCode = fence(...args).replace(
/<pre /g,
`<pre class="language-${token.info?.trim()}" `,
);
return rawCode; //`<div class="language-${token.info.trim()}">${rawCode}</div>`;
};
};

View File

@ -25,7 +25,7 @@ export const snippetPlugin = (md: MarkdownIt, root: string) => {
const start = pos + 3;
const end = state.skipSpacesBack(max, pos);
const rawPath = state.src.slice(start, end)?.trim().replace(/^@/, root);
const filename = rawPath.split(/{/).shift()!.trim();
const filename = rawPath.split(/{/).shift()?.trim();
const content = fs.existsSync(filename)
? fs.readFileSync(filename).toString()
: 'Not found: ' + filename;

View File

@ -69,7 +69,7 @@ ${fetchCode(content, 'style')}
debug(`[render] ${file} in ${Date.now() - start}ms.`);
const result = {
vueSrc: newContent.trim(),
vueSrc: newContent?.trim(),
pageData,
};
cache.set(src, result);
@ -91,7 +91,7 @@ ${vueCode?.trim()}
const script = fetchCode(vueCode, 'script');
const style = fetchCode(vueCode, 'style');
const scriptContent = fetchCode(vueCode, 'scriptContent');
let jsCode = (await tsToJs(scriptContent)).trim();
let jsCode = (await tsToJs(scriptContent))?.trim();
jsCode = jsCode
? `<script>
${jsCode}
@ -146,7 +146,7 @@ const inferTitle = (frontmatter: any, content: string) => {
}
const match = content.match(/^\s*#+\s+(.*)/m);
if (match) {
return deeplyParseHeader(match[1].trim());
return deeplyParseHeader(match[1]?.trim());
}
return '';
};

View File

@ -31,7 +31,7 @@ const removeMarkdownTokens = (str: string) =>
// eslint-disable-next-line no-useless-escape
.replace(/(\\)(\*|_|`|\!|<|\$)/g, '$2'); // remove escape char '\'
const trim = (str: string) => str.trim();
const trim = (str = '') => str?.trim();
// This method remove the raw HTML but reserve the HTML wrapped by `<code>`.
// e.g.