Skip to content

Commit 6ddaa70

Browse files
committed
fix: fix title anchor preprocessor
1 parent 517c3c1 commit 6ddaa70

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

docs/.vitepress/theme/anchor/titleAnchorPreprocessor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import slugifyTitle from "./slugify";
44
export const titleAnchorPreprocessor = (md: MarkdownIt) => {
55
md.core.ruler.before('normalize', 'title-anchor', (state) => {
66
const lines = state.src.split("\n");
7+
let inCodeBlock = false;
78
const processedLines = lines.map((line) => {
9+
if (line.startsWith("```")) {
10+
inCodeBlock = !inCodeBlock;
11+
}
12+
if (inCodeBlock) {
13+
return line;
14+
}
815
if (line.startsWith("#")) {
916
const title = line.replace(new RegExp("#", "g"), "");
1017
const processedTitle = (line.includes("{") && line.includes("}")) ?

0 commit comments

Comments
 (0)