Skip to content
Open
Show file tree
Hide file tree
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
25 changes: 14 additions & 11 deletions src/report/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ function renderSection(
.filter((change) => change.canonical)
.map(
(change) =>
`<span class="change-target" id="${change.fragment}" data-target-kind="change"></span>`,
`<a class="change-target" id="${change.fragment}" data-target-kind="change" href="#${change.fragment}">${escapeHtml(change.id)}</a>`,
)
.join('')
const actions = `<div class="step-actions">
${renderPermalink(stepTarget.fragment, `Permalink to step ${stepIndex + 1} in ${section.title}`, 'LINK')}${changeTargets}
${renderPermalink(stepTarget.fragment, `Permalink to step ${stepIndex + 1} in ${section.title}`, linkIcon)}${changeTargets}
</div>`
if (step.diff === undefined && step.binary === undefined) {
return `<div class="step" id="${stepTarget.fragment}" data-step-index="${stepIndex}" data-target-kind="step">${actions}${textMarkup}</div>`
Expand Down Expand Up @@ -266,8 +266,12 @@ ${links}
</nav>`
}

function renderPermalink(fragment: string, label: string, text: string): string {
return `<a class="permalink" href="#${fragment}" aria-label="${escapeHtml(label)}">${escapeHtml(text)}</a>`
// The link glyph is markup, not text, so the caller owns the escaping.
const linkIcon =
'<svg class="permalink-icon" viewBox="0 0 16 16" width="11" height="11" aria-hidden="true" focusable="false"><g fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"><path d="M6.4 9.6 9.6 6.4"/><path d="M7 4.4 8.6 2.8a3 3 0 0 1 4.6 3.8l-1.8 1.8"/><path d="M9 11.6 7.4 13.2a3 3 0 0 1-4.6-3.8l1.8-1.8"/></g></svg>'

function renderPermalink(fragment: string, label: string, content: string): string {
return `<a class="permalink" href="#${fragment}" aria-label="${escapeHtml(label)}">${content}</a>`
}

function pluralize(count: number, noun: string): string {
Expand Down Expand Up @@ -495,12 +499,11 @@ main { max-width: none; min-width: 0; margin: 0; padding: 22px 28px 72px; }
.section-fold[open] > summary { border-bottom-color: var(--border); }
.prose { color: #3c4d41; font-size: 14px; }
.step { position: relative; scroll-margin-top: 18px; }
.step-actions { position: absolute; top: 8px; right: 12px; z-index: 2; }
.step-text { max-width: 900px; padding: 8px 68px 8px 20px; font-size: 17px; }
.permalink { display: block; padding: 2px 3px; color: #98a29c; font: 600 10px/20px ui-monospace, SFMono-Regular, Menlo, monospace; text-decoration: none; }
.permalink:hover, .permalink:focus-visible { color: var(--accent); }
.change-target { position: absolute; top: 0; left: 0; width: 0; height: 0; overflow: hidden; scroll-margin-top: 18px; }
.step:not(:has(.step-text)) .step-files { padding-right: 68px; }
.step-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 8px 20px 0; }
.step-text { max-width: 900px; padding: 4px 20px 8px; font-size: 17px; }
.permalink, .change-target { display: inline-flex; align-items: center; border-radius: 5px; padding: 2px 6px; color: #98a29c; font: 600 10px/14px ui-monospace, SFMono-Regular, Menlo, monospace; text-decoration: none; }
.permalink:hover, .permalink:focus-visible, .change-target:hover, .change-target:focus-visible { color: var(--accent); background: #eef5ef; }
.change-target { scroll-margin-top: 18px; }
.prose strong { color: #142c1d; }
.step-files { padding: 12px; display: grid; gap: 9px; }
.step + .step { border-top: 1px solid #e3ebe5; }
Expand Down Expand Up @@ -627,7 +630,7 @@ main { max-width: none; min-width: 0; margin: 0; padding: 22px 28px 72px; }
.section-fold > summary { font-size: 17px; }
}
@media print {
.layout-form, .permalink { display: none; }
.layout-form, .permalink, .change-target { display: none; }
.review-map { display: none; }
.review-workspace { display: block; }
.report-cover { box-shadow: none; break-inside: avoid; }
Expand Down
7 changes: 5 additions & 2 deletions test/report-dom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,10 +795,13 @@ describe('report browser client', () => {
expect(title.tagName).toBe('A')
expect(title.textContent).toBe('Linked title')
expect(title.tabIndex).toBe(0)
expect(stepLink.textContent).toBe('LINK')
expect(stepLink.getAttribute('href')).toBe(`#${stepLink.closest('.step')!.id}`)
expect(stepLink.querySelector('svg')).not.toBeNull()
expect(stepLink.tabIndex).toBe(0)
expect(doc.querySelector('[data-copy-fragment]')).toBeNull()
expect(doc.querySelector('a[href="#change-001"]')).toBeNull()
expect(doc.querySelector<HTMLAnchorElement>('a[href="#change-001"]')?.textContent).toBe(
'change-001',
)

button.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true, cancelable: true }) as unknown as Event)
expect(fold.open).toBe(false)
Expand Down
9 changes: 5 additions & 4 deletions test/report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ describe('renderReport shell', () => {
expect(html).not.toContain('id="section-0-step-0-file-0"')
})

test('section titles and step markers are links while change targets stay empty', () => {
test('section titles and step markers are links while change targets name themselves', () => {
const value = document([{
title: 'Linkable',
steps: [{ text: 'A linkable step.', diff: simplePatch(), changes: ['change-001'] }],
Expand All @@ -452,10 +452,11 @@ describe('renderReport shell', () => {

expect(html).toContain(`<a class="section-title-text" href="#${target.fragment}">Linkable</a>`)
expect(html).toContain(
`<a class="permalink" href="#${target.steps[0]!.fragment}" aria-label="Permalink to step 1 in Linkable">LINK</a>`,
`<a class="permalink" href="#${target.steps[0]!.fragment}" aria-label="Permalink to step 1 in Linkable"><svg class="permalink-icon"`,
)
expect(html).toContain(
'<a class="change-target" id="change-001" data-target-kind="change" href="#change-001">change-001</a>',
)
expect(html).toContain('id="change-001" data-target-kind="change"></span>')
expect(html).not.toContain('href="#change-001"')
expect(html).not.toContain('data-copy-fragment')
})

Expand Down