Skip to content

Commit

Permalink
fix anchor parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Aug 5, 2023
1 parent da938d8 commit 75ac9c8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/components/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import {readdir, readFile, stat} from "fs/promises";

// Anchors can be derived from headers, or explicitly written as {#names}.
export function getAnchors(text) {
text = text.replace(/<(?:Version)?Badge[^/]*\/>/g, ""); // ignore badges
const anchors = [];
for (const [, header] of text.matchAll(/^#+ ([*\w][*().,\w\d -]+)\n/gm)) {
anchors.push(
header
.replaceAll(/[^\w\d\s]+/g, " ")
.replace(/[^\w\d\s]+/g, " ")
.trim()
.replaceAll(/ +/g, "-")
.replace(/ +/g, "-")
.toLowerCase()
);
}
Expand Down

0 comments on commit 75ac9c8

Please sign in to comment.