Skip to content

Commit 9835ea7

Browse files
authored
fix(language-core): replace markdown links after sfc blocks processing (#5695)
Partial revert #5497
1 parent c99b0ab commit 9835ea7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/language-core/lib/plugins/file-md.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const codeblockReg = /(`{3,})[\s\S]+?\1/g;
1010
const inlineCodeblockReg = /`[^\n`]+?`/g;
1111
const latexBlockReg = /(\${2,})[\s\S]+?\1/g;
1212
const scriptSetupReg = /\\<[\s\S]+?>\n?/g;
13+
const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
14+
const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
1315
const angleBracketReg = /<\S*:\S*>/g;
1416
const linkReg = /\[[\s\S]*?\]\([\s\S]*?\)/g;
15-
const sfcBlockReg = /<(script|style)\b[\s\S]*?>([\s\S]*?)<\/\1>/g;
16-
const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
1717

1818
const plugin: VueLanguagePlugin = ({ vueCompilerOptions }) => {
1919
return {
@@ -46,11 +46,7 @@ const plugin: VueLanguagePlugin = ({ vueCompilerOptions }) => {
4646
// # \<script setup>
4747
.replace(scriptSetupReg, match => ' '.repeat(match.length))
4848
// <<< https://vitepress.dev/guide/markdown#import-code-snippets
49-
.replace(codeSnippetImportReg, match => ' '.repeat(match.length))
50-
// angle bracket: <http://foo.com>
51-
.replace(angleBracketReg, match => ' '.repeat(match.length))
52-
// [foo](http://foo.com)
53-
.replace(linkReg, match => ' '.repeat(match.length));
49+
.replace(codeSnippetImportReg, match => ' '.repeat(match.length));
5450

5551
const codes: Segment[] = [];
5652

@@ -62,6 +58,12 @@ const plugin: VueLanguagePlugin = ({ vueCompilerOptions }) => {
6258
+ content.slice(match.index + matchText.length);
6359
}
6460

61+
content = content
62+
// angle bracket: <http://foo.com>
63+
.replace(angleBracketReg, match => ' '.repeat(match.length))
64+
// [foo](http://foo.com)
65+
.replace(linkReg, match => ' '.repeat(match.length));
66+
6567
codes.push('<template>\n');
6668
codes.push([content, undefined, 0]);
6769
codes.push('\n</template>');

0 commit comments

Comments
 (0)