Skip to content

Commit 16f5c2e

Browse files
committed
feat: improve title anchor with custom anchor
1 parent 6ac7a33 commit 16f5c2e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export const titleAnchorPreprocessor = (md: MarkdownIt) => {
77
const processedLines = lines.map((line) => {
88
if (line.startsWith("#")) {
99
const title = line.replace(new RegExp("#", "g"), "");
10-
const processedTitle = slugifyTitle(title);
10+
const processedTitle = (line.includes("{") && line.includes("}")) ?
11+
extractAnchor(title) : slugifyTitle(title);
1112
return `
1213
1314
<TitleAnchor anchor="${processedTitle}">
@@ -24,3 +25,7 @@ ${line}
2425
state.src = processedLines.join("\n");
2526
});
2627
}
28+
29+
function extractAnchor(title: string): string {
30+
return title.split("{")[1].split("}")[0];
31+
}

0 commit comments

Comments
 (0)