Skip to content

Commit 727fc3d

Browse files
committed
strip links
1 parent 5529642 commit 727fc3d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

scripts/generateHeadingIDs.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ function walk(dir) {
1818
return results;
1919
}
2020

21+
function stripLinks(line) {
22+
return line.replace(/\[([^\]]+)\]\([^)]+\)/, (match, p1) => p1);
23+
}
24+
2125
function addHeaderID(line, slugger) {
2226
// check if we're a header at all
2327
if (!line.startsWith('#')) {
@@ -27,7 +31,10 @@ function addHeaderID(line, slugger) {
2731
if (/\{#[^}]+\}/.test(line)) {
2832
return line;
2933
}
30-
const headingText = line.slice(line.indexOf(' ')).trim();
34+
if (/\[[^\]]+\]/.test(line)) {
35+
console.log(line);
36+
}
37+
const headingText = stripLinks(line.slice(line.indexOf(' ')).trim());
3138
const headingLevel = line.slice(0, line.indexOf(' '));
3239
return `${headingLevel} ${headingText} {#${slugger.slug(headingText)}}`;
3340
}

0 commit comments

Comments
 (0)