Skip to content

Commit 483d790

Browse files
committed
fix(website): address review issues on PR #7
- changelog: underline the Keep a Changelog head link so color isn't the only link indicator (matches prose links elsewhere) - changelog: replace the set:html markdown regex with a tokenizing renderer; bullets render as real strong/code elements through text nodes, so unmatched ** and backticks stay literal and no HTML can reach the DOM - docs article: scope .docs-edit a to keep the edit-on-GitHub footer link muted and non-underlined despite the new prose link rule
1 parent 9aca0d0 commit 483d790

2 files changed

Lines changed: 48 additions & 11 deletions

File tree

‎website/src/pages/changelog.astro‎

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,41 @@ import { loadChangelog } from '~/lib/changelog';
66
77
const releases = loadChangelog();
88
9-
// Bullets are raw markdown lines. Escape HTML, then render the two inline
10-
// constructs CHANGELOG.md actually uses: **bold** and `code`.
11-
const inline = (s: string) =>
12-
s
13-
.replace(/&/g, '&')
14-
.replace(/</g, '&lt;')
15-
.replace(/>/g, '&gt;')
16-
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
17-
.replace(/`([^`]+?)`/g, '<code>$1</code>');
9+
// Bullets are raw markdown lines. Tokenize the two inline constructs
10+
// CHANGELOG.md actually uses — **bold** and `code` — into segments rendered
11+
// as real elements. Unmatched markers stay literal text, and since output is
12+
// text nodes, arbitrary HTML in a bullet can never reach the DOM.
13+
interface InlineToken {
14+
text: string;
15+
bold?: boolean;
16+
code?: boolean;
17+
}
18+
19+
function tokenizeInline(s: string): InlineToken[] {
20+
const tokens: InlineToken[] = [];
21+
let rest = s;
22+
while (rest) {
23+
const bi = rest.indexOf('**');
24+
const ci = rest.indexOf('`');
25+
if (bi === -1 && ci === -1) break;
26+
const useBold = bi !== -1 && (ci === -1 || bi < ci);
27+
if (useBold) {
28+
const end = rest.indexOf('**', bi + 2);
29+
if (end === -1) break;
30+
if (bi > 0) tokens.push({ text: rest.slice(0, bi) });
31+
tokens.push({ text: rest.slice(bi + 2, end), bold: true });
32+
rest = rest.slice(end + 2);
33+
} else {
34+
const end = rest.indexOf('`', ci + 1);
35+
if (end === -1) break;
36+
if (ci > 0) tokens.push({ text: rest.slice(0, ci) });
37+
tokens.push({ text: rest.slice(ci + 1, end), code: true });
38+
rest = rest.slice(end + 1);
39+
}
40+
}
41+
if (rest) tokens.push({ text: rest });
42+
return tokens;
43+
}
1844
---
1945
<BaseLayout
2046
title="Changelog"
@@ -39,7 +65,13 @@ const inline = (s: string) =>
3965
<section>
4066
<h3>{s.type[0].toUpperCase()}{s.type.slice(1)}</h3>
4167
<ul role="list">
42-
{s.bullets.map((b) => <li set:html={inline(b)} />)}
68+
{s.bullets.map((b) => (
69+
<li>
70+
{tokenizeInline(b).map((t) =>
71+
t.bold ? <strong>{t.text}</strong> : t.code ? <code>{t.text}</code> : t.text,
72+
)}
73+
</li>
74+
))}
4375
</ul>
4476
</section>
4577
))}
@@ -54,7 +86,7 @@ const inline = (s: string) =>
5486
.cl__head { text-align: center; margin-bottom: 3rem; }
5587
.cl__head h1 { font-size: clamp(2.4rem, 6vw, 3.4rem); margin: 0; }
5688
.cl__head p { color: var(--muted-foreground); margin-top: 0.6rem; }
57-
.cl__head a { color: var(--primary); }
89+
.cl__head a { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
5890
.cl__rel { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem 1.8rem; margin-bottom: 1.5rem; }
5991
.cl__rel--latest { border-color: color-mix(in oklab, var(--primary) 45%, transparent); }
6092
.cl__pill {

‎website/src/pages/docs/[...slug].astro‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ const groupTitles: Record<string, string> = {
165165
}
166166
.docs-article :global(p) { line-height: 1.7; }
167167
.docs-article :global(a) { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
168+
.docs-article :global(.docs-edit a) {
169+
color: var(--muted-foreground);
170+
text-decoration: none;
171+
}
172+
.docs-article :global(.docs-edit a:hover) { color: var(--foreground); }
168173
.docs-article :global(code) {
169174
font-family: var(--font-mono);
170175
background: var(--muted);

0 commit comments

Comments
 (0)