Skip to content

Commit

Permalink
Prepend markdown anchor links with '#md:'
Browse files Browse the repository at this point in the history
  • Loading branch information
mogelbrod authored and Gerrit0 committed Oct 28, 2023
1 parent 99f7a12 commit 41e6b33
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/output/themes/MarkedPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ output file :
if (!markedOptions.renderer) {
markedOptions.renderer = new Marked.Renderer();

markedOptions.renderer.link = (href, title, text) => {
// Prefix the #anchor links `#md:`.
href =
href
?.replace(/^#(?:md:)?(.+)/, "#md:$1")
.replace(/"/g, """) || "";
let html = `<a href="${href}"`;
if (title != null)
html += ` title="${title.replace(/"/g, "&quot;")}"`;
html += `>${text}</a>`;
return html;
};

markedOptions.renderer.heading = (text, level, _, slugger) => {
const slug = slugger.slug(text);
// Prefix the slug with an extra `md:` to prevent conflicts with TypeDoc's anchors.
Expand Down

0 comments on commit 41e6b33

Please sign in to comment.