doc: update md plugin

pull/4940/head
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 ## en-US
Read only, can't use mouse to interact. Read only, can't use mouse to interact.
</docs> </docs>
<template> <template>
<a-rate :value="2" disabled /> <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> </docs>
<template> <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"> <div v-if="false">
you can visit you can visit
<a href="https://www.surely.cool" /> <a href="https://www.surely.cool"></a>
get more info get more info
</div> </div>
</template> </template>

View File

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

View File

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

View File

@ -16,10 +16,13 @@ export const preWrapperPlugin = (md: MarkdownIt) => {
const [tokens, idx] = args; const [tokens, idx] = args;
const token = tokens[idx]; const token = tokens[idx];
const data = (md as any).__data as MarkdownParsedData; const data = (md as any).__data as MarkdownParsedData;
if (token.info.trim() === 'vue') { if (token.info?.trim() === 'vue') {
data.vueCode = token.content; 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>`; 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 start = pos + 3;
const end = state.skipSpacesBack(max, pos); const end = state.skipSpacesBack(max, pos);
const rawPath = state.src.slice(start, end)?.trim().replace(/^@/, root); 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) const content = fs.existsSync(filename)
? fs.readFileSync(filename).toString() ? fs.readFileSync(filename).toString()
: 'Not found: ' + filename; : 'Not found: ' + filename;

View File

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

View File

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