This commit is contained in:
Chris Tate
2026-04-06 19:59:03 -05:00
committed by GitHub
parent b75fba130b
commit c4e0f9d367
2 changed files with 42 additions and 2 deletions
+21 -2
View File
@@ -27,13 +27,32 @@ function extractText(children: React.ReactNode): string {
export function useMDXComponents(components: MDXComponents): MDXComponents { export function useMDXComponents(components: MDXComponents): MDXComponents {
return { return {
...components, ...components,
h1: ({ children }: { children?: React.ReactNode }) => {
const id = slugify(extractText(children));
return (
<h1 id={id} className="heading-anchor">
{children}
<a href={`#${id}`} aria-label="Link to this section">#</a>
</h1>
);
},
h2: ({ children }: { children?: React.ReactNode }) => { h2: ({ children }: { children?: React.ReactNode }) => {
const id = slugify(extractText(children)); const id = slugify(extractText(children));
return <h2 id={id}>{children}</h2>; return (
<h2 id={id} className="heading-anchor">
{children}
<a href={`#${id}`} aria-label="Link to this section">#</a>
</h2>
);
}, },
h3: ({ children }: { children?: React.ReactNode }) => { h3: ({ children }: { children?: React.ReactNode }) => {
const id = slugify(extractText(children)); const id = slugify(extractText(children));
return <h3 id={id}>{children}</h3>; return (
<h3 id={id} className="heading-anchor">
{children}
<a href={`#${id}`} aria-label="Link to this section">#</a>
</h3>
);
}, },
a: ({ a: ({
href, href,
+21
View File
@@ -201,6 +201,27 @@ pre:not(.shiki) {
color: var(--foreground); color: var(--foreground);
} }
.prose .heading-anchor {
position: relative;
}
.prose .heading-anchor > a {
opacity: 0;
margin-left: 0.375rem;
color: var(--muted-foreground);
text-decoration: none;
font-weight: 400;
transition: opacity 0.15s ease;
}
.prose .heading-anchor:hover > a {
opacity: 1;
}
.prose .heading-anchor > a:hover {
color: var(--foreground);
}
.prose p { .prose p {
margin-bottom: 1rem; margin-bottom: 1rem;
line-height: 1.65; line-height: 1.65;