Skip to content

Commit beca777

Browse files
committed
feat: add clickable links to readme headings
1 parent 4ebabb2 commit beca777

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

app/components/Readme.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ function handleClick(event: MouseEvent) {
150150
@apply inline i-carbon:launch rtl-flip ms-1 opacity-50;
151151
}
152152
153+
.readme :deep(a[href^='#']::after) {
154+
/* I don't know what kind of sorcery this is, but it ensures this icon can't wrap to a new line on its own. */
155+
content: '__';
156+
@apply inline i-carbon:link rtl-flip ms-1 opacity-0;
157+
}
158+
159+
.readme :deep(a[href^='#']:hover::after) {
160+
@apply opacity-100;
161+
}
162+
153163
.readme :deep(code) {
154164
@apply font-mono;
155165
font-size: 0.875em;

server/utils/readme.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ export async function renderReadmeHtml(
377377
toc.push({ text: plainText, id, depth })
378378
}
379379

380-
return `<h${semanticLevel} id="${id}" data-level="${depth}">${text}</h${semanticLevel}>\n`
380+
/** The link href uses the unique slug WITHOUT the 'user-content-' prefix, because that will later be added for all links. */
381+
return `<h${semanticLevel} id="${id}" data-level="${depth}"><a href="#${uniqueSlug}">${text}</a></h${semanticLevel}>\n`
381382
}
382383

383384
// Syntax highlighting for code blocks (uses shared highlighter)

0 commit comments

Comments
 (0)