docs: add canary docs for <head> modifications (#3173)

Adds v2 version of "Modyfing the <head>" example. This is the next to
last page that needs to be updated (though the other only requires minor
changes to types).
This commit is contained in:
Christian Svensson
2025-08-05 23:50:58 +02:00
committed by GitHub
parent 4818faad1d
commit e014d80a0f
5 changed files with 212 additions and 4 deletions
+12 -2
View File
@@ -31,6 +31,12 @@ function setActiveLink(
marker.style.cssText = `transform: translate3d(0, ${top}px, 0); opacity: 1`;
}
function hLevelToClass(level: number): string {
if (level === 3) return "ml-4";
if (level === 4) return "ml-8";
return "";
}
export function TableOfContents({ headings }: TableOfContentsProps) {
const ref = useRef<HTMLDivElement>(null);
const refMarker = useRef<HTMLDivElement>(null);
@@ -127,7 +133,9 @@ export function TableOfContents({ headings }: TableOfContentsProps) {
<li key={heading.id}>
<a
href={`#${heading.id}`}
class="block truncatetext-gray-600 dark:text-gray-400"
class={`block ${
hLevelToClass(heading.level)
} truncate text-gray-600 dark:text-gray-400`}
// deno-lint-ignore react-no-danger
dangerouslySetInnerHTML={{ __html: heading.html }}
/>
@@ -159,7 +167,9 @@ export function TableOfContents({ headings }: TableOfContentsProps) {
<li key={heading.id}>
<a
href={`#${heading.id}`}
class="block truncate transition-colors text-gray-600 dark:text-gray-400 [&.active]:text-green-600 dark:[&.active]:text-green-300"
class={`block truncate transition-colors ${
hLevelToClass(heading.level)
} text-gray-600 dark:text-gray-400 [&.active]:text-green-600 dark:[&.active]:text-green-300`}
onClick={() => {
setActiveLink(
ref.current!,
+2 -1
View File
@@ -82,6 +82,7 @@ const LOGOS = [
export interface MarkdownHeading {
id: string;
html: string;
level: number;
}
class DefaultRenderer extends Marked.Renderer {
@@ -127,7 +128,7 @@ class DefaultRenderer extends Marked.Renderer {
const slug = slugger.slug(slugInput);
const text = this.parser.parseInline(tokens);
this.headings.push({ id: slug, html: text });
this.headings.push({ id: slug, html: text, level: depth });
return `<h${depth} id="${slug}"><a class="md-anchor" tabindex="-1" href="#${slug}">${text}<span aria-hidden="true">#</span></a></h${depth}>`;
}