Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a header anchor link to every header rendered from commentary #2079

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/components/Markdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
start ? `start="${start}"` : ""
} class="mzp-u-list-styled">${body}</${outerEl}>`;
},
heading(text, level, raw) {
const id = raw
.toLowerCase()
.trim()
.replace(/<[!/a-z].*?>/gi, "")
badboy marked this conversation as resolved.
Show resolved Hide resolved
.replace(/ +/g, "-");

return `<h${level} class="annotation-header-link" id="${id}"><a href="#${id}">${text}</a></h${level}>\n`;
badboy marked this conversation as resolved.
Show resolved Hide resolved
},
};
use({ renderer });

Expand All @@ -24,5 +33,26 @@
{#if inline}
{@html parseInline(text)}
{:else}
{@html parse(text)}
<div>
{@html parse(text)}
</div>
{/if}

<style lang="scss">
div :global(h1 a),
div :global(h2 a),
div :global(h3 a),
div :global(h4 a),
div :global(h5 a) {
color: black;
text-decoration: none;
}

div :global(h1 a:hover),
div :global(h2 a:hover),
div :global(h3 a:hover),
div :global(h4 a:hover),
div :global(h5 a:hover) {
text-decoration: underline;
}
</style>