Skip to content

Commit 3a141b2

Browse files
committed
doc: update md plugin
1 parent b07882d commit 3a141b2

File tree

8 files changed

+14
-12
lines changed

8 files changed

+14
-12
lines changed

components/rate/demo/disabled.vue

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ title:
1313
## en-US
1414

1515
Read only, can't use mouse to interact.
16-
1716
</docs>
1817
<template>
1918
<a-rate :value="2" disabled />

components/table/demo/big-data.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ Using this component, you can smoothly scroll through 100,000 rows and 100,000 c
1919
</docs>
2020

2121
<template>
22-
<iframe src="https://www.surely.cool/for-ant-demo" height="400" />
22+
<iframe src="https://www.surely.cool/for-ant-demo" height="400"></iframe>
2323
<div v-if="false">
2424
you can visit
25-
<a href="https://www.surely.cool" />
25+
<a href="https://www.surely.cool"></a>
2626
get more info
2727
</div>
2828
</template>

plugin/md/markdown/plugins/containers.ts

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

plugin/md/markdown/plugins/hoist.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const hoistPlugin = (md: MarkdownIt) => {
77
const RE = /^<(script|style)(?=(\s|>|$))/i;
88

99
md.renderer.rules.html_block = (tokens, idx) => {
10-
const content = tokens[idx].content;
10+
const content = tokens[idx].content || '';
1111
const data = (md as any).__data as MarkdownParsedData;
1212
const hoistedTags = data.hoistedTags || (data.hoistedTags = []);
1313
if (RE.test(content.trim())) {

plugin/md/markdown/plugins/preWrapper.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ export const preWrapperPlugin = (md: MarkdownIt) => {
1616
const [tokens, idx] = args;
1717
const token = tokens[idx];
1818
const data = (md as any).__data as MarkdownParsedData;
19-
if (token.info.trim() === 'vue') {
19+
if (token.info?.trim() === 'vue') {
2020
data.vueCode = token.content;
2121
}
22-
const rawCode = fence(...args).replace(/<pre /g, `<pre class="language-${token.info.trim()}" `);
22+
const rawCode = fence(...args).replace(
23+
/<pre /g,
24+
`<pre class="language-${token.info?.trim()}" `,
25+
);
2326
return rawCode; //`<div class="language-${token.info.trim()}">${rawCode}</div>`;
2427
};
2528
};

plugin/md/markdown/plugins/snippet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const snippetPlugin = (md: MarkdownIt, root: string) => {
2525
const start = pos + 3;
2626
const end = state.skipSpacesBack(max, pos);
2727
const rawPath = state.src.slice(start, end)?.trim().replace(/^@/, root);
28-
const filename = rawPath.split(/{/).shift()!.trim();
28+
const filename = rawPath.split(/{/).shift()?.trim();
2929
const content = fs.existsSync(filename)
3030
? fs.readFileSync(filename).toString()
3131
: 'Not found: ' + filename;

plugin/md/markdownToVue.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ ${fetchCode(content, 'style')}
6969

7070
debug(`[render] ${file} in ${Date.now() - start}ms.`);
7171
const result = {
72-
vueSrc: newContent.trim(),
72+
vueSrc: newContent?.trim(),
7373
pageData,
7474
};
7575
cache.set(src, result);
@@ -91,7 +91,7 @@ ${vueCode?.trim()}
9191
const script = fetchCode(vueCode, 'script');
9292
const style = fetchCode(vueCode, 'style');
9393
const scriptContent = fetchCode(vueCode, 'scriptContent');
94-
let jsCode = (await tsToJs(scriptContent)).trim();
94+
let jsCode = (await tsToJs(scriptContent))?.trim();
9595
jsCode = jsCode
9696
? `<script>
9797
${jsCode}
@@ -146,7 +146,7 @@ const inferTitle = (frontmatter: any, content: string) => {
146146
}
147147
const match = content.match(/^\s*#+\s+(.*)/m);
148148
if (match) {
149-
return deeplyParseHeader(match[1].trim());
149+
return deeplyParseHeader(match[1]?.trim());
150150
}
151151
return '';
152152
};

plugin/md/utils/parseHeader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const removeMarkdownTokens = (str: string) =>
3131
// eslint-disable-next-line no-useless-escape
3232
.replace(/(\\)(\*|_|`|\!|<|\$)/g, '$2'); // remove escape char '\'
3333

34-
const trim = (str: string) => str.trim();
34+
const trim = (str = '') => str?.trim();
3535

3636
// This method remove the raw HTML but reserve the HTML wrapped by `<code>`.
3737
// e.g.

0 commit comments

Comments
 (0)