diff --git a/scripts/docs-site/docs-layout.css b/scripts/docs-site/docs-layout.css index 82e365aace..f087d3ef10 100644 --- a/scripts/docs-site/docs-layout.css +++ b/scripts/docs-site/docs-layout.css @@ -214,8 +214,8 @@ @media (prefers-reduced-motion:reduce) { .docs-layout .doc .release-source-toggle > summary::before { transition: none; }} .docs-layout .doc .release-source-toggle > summary:focus-visible { outline: 2px solid var(--oc-focus-ring); outline-offset: 2px; } -/* Patch lists keep their detail control in the sentence's inline flow. */ -.docs-layout .doc li:has(> .release-source-inline) > p:first-child { display: inline; margin: 0; } +/* A single point or a list item shares its last line with its source toggle. */ +.docs-layout .doc p:has(+ details.release-source-inline) { display: inline; margin: 0; } .docs-layout .doc .release-source-inline { display: inline; } .docs-layout .doc .release-source-inline > summary { display: inline-flex; vertical-align: middle; min-block-size: 0; inline-size: 20px; block-size: 20px; justify-content: center; margin-inline-start: .2em; padding: 0; border-radius: 4px; color: var(--muted); font-size: 0; line-height: 0; position: relative; } /* Inline patch-release details: a small chevron only; the label stays for assistive tech. */ diff --git a/scripts/docs-site/mdx-ish.mjs b/scripts/docs-site/mdx-ish.mjs index 4d2462a771..586a5d1d9c 100644 --- a/scripts/docs-site/mdx-ish.mjs +++ b/scripts/docs-site/mdx-ish.mjs @@ -20,6 +20,7 @@ import typescript from "highlight.js/lib/languages/typescript"; import xml from "highlight.js/lib/languages/xml"; import yaml from "highlight.js/lib/languages/yaml"; import { icons as lucideIcons } from "lucide"; +import { attachReleasePointToggles } from "./release-point-toggles.mjs"; import { frameArticleMedia } from "./media-scenes.mjs"; const languages = { @@ -209,7 +210,7 @@ function mermaidHtml(source) { export function renderMdxish(markdown, md, options) { const { tokens, env } = parseDocsDocument(markdown, md, options); - return rewriteDocsRelativeLinks(frameArticleMedia(postprocess(md.renderer.render(tokens, md.options, env))), options); + return rewriteDocsRelativeLinks(frameArticleMedia(attachReleasePointToggles(postprocess(md.renderer.render(tokens, md.options, env)))), options); } function postprocess(html) { diff --git a/scripts/docs-site/release-inline-details.test.mjs b/scripts/docs-site/release-inline-details.test.mjs index d7edfa2f54..384ca23b56 100644 --- a/scripts/docs-site/release-inline-details.test.mjs +++ b/scripts/docs-site/release-inline-details.test.mjs @@ -19,13 +19,15 @@ test("patch details follow the fix inline and retain native keyboard access", as `; const css = fs.readFileSync(new URL("./docs-layout.css", import.meta.url), "utf8"); try { - for (const width of [1200, 390]) { + for (const shape of ["list", "grouped-list", "single"]) for (const width of [1200, 390]) { const page = await browser.newPage({ viewport: { width, height: 700 } }); try { - await page.setContent(`
${renderMdxish(source, createMarkdownRenderer())}
`); + await page.setContent(`
${renderMdxish(shape === "list" ? source : `\n\n\n${shape === "single" ? source.split("- An unrelated")[0].slice(2).replace(/^ /gm, "") : source}\n\n`, createMarkdownRenderer())}
`); + if (shape !== "list") await page.locator(".oc-accordion > summary").click(); const summary = page.locator(".release-source-inline > summary"); const link = page.getByRole("link", { name: "#123", exact: true }); assert.equal(await link.isVisible(), false); + await summary.scrollIntoViewIfNeeded(); const layout = await summary.evaluate((element) => { const paragraph = element.parentElement.previousElementSibling; const range = document.createRange(); @@ -42,9 +44,9 @@ test("patch details follow the fix inline and retain native keyboard access", as }); assert.equal(layout.paragraphDisplay, "inline"); assert.ok(layout.control.height <= 24, "keep the visible control compact"); - assert.equal(layout.pointerArea, true, "retain a 44px pointer target around the control"); + assert.equal(layout.pointerArea, true, `retain a 44px pointer target (shape=${shape}, width=${width}): ${JSON.stringify(layout)}`); assert.equal(layout.overflow, false, "narrow view must not scroll horizontally"); - if (width === 1200) { + { assert.ok(layout.control.left >= layout.end.right, "control follows the final character"); assert.ok(layout.control.top < layout.end.bottom && layout.control.bottom > layout.end.top, "control and sentence share a line"); } @@ -63,3 +65,12 @@ test("patch details follow the fix inline and retain native keyboard access", as } } finally { await browser.close(); } }); + + +test("consecutive source records for one release point keep their links under one toggle", () => { + const record = n => `
\nMore details\n\n[#${n}](https://github.com/example/repo/pull/${n}).\n\n
`; + const html=renderMdxish(`\n\nFinal [link](https://example.org).\n\n${record(12)}\n\n${record(34)}\n\n`,createMarkdownRenderer()); + assert.equal(html.match(/More details/g)?.length,1); + assert.match(html,/⁠<\/p>
node?.attribs?.class?.split(/\s+/).includes(name); + const nonblank = n => n.type !== 'text' || n.data.trim(); + for (const details of DomUtils.findAll(n => n.name === 'details' && hasClass(n, 'release-source-inline'), tree.children)) { + if (!hasClass(details.parent, 'oc-accordion-content')) continue; + let list = details.prev; + while (list && !nonblank(list)) list = list.prev; + if (list?.name !== 'ul') continue; + const item = list.children.findLast(nonblank); + if (item?.name !== 'li') continue; + const content = item.children.filter(nonblank); + if (!content.length || content.some(n => ['ul', 'ol', 'details', 'div', 'pre', 'table'].includes(n.name))) continue; + const start = item.startIndex + html.slice(item.startIndex, content[0].startIndex).indexOf('>') + 1; + const end = item.endIndex + 1 - ''.length; + const body = html.slice(start, end); + const paragraph = content.some(n => n.name === 'p') ? body : `

${body}

`; + edits.push([start, details.endIndex + 1, paragraph + '\n' + html.slice(details.startIndex, details.endIndex + 1) + '\n\n']); + } + const result = []; let pos = 0; + for (const [start,end,markup] of edits) { result.push(html.slice(pos,start),markup); pos=end; } + const attached = result.join('') + html.slice(pos); + // A plain space between an inline paragraph and its control is a legal line + // break. Bind the last word to the control even near a narrow right edge. + // Adjacent unlabeled source records for one point share one disclosure; + // never collapse anchors, custom summaries or author-specified attributes. + const nodes = parseDocument(attached, { withStartIndices: true, withEndIndices: true }); + const standard = n => n?.name === 'details' && Object.keys(n.attribs).length === 1 && + hasClass(n, 'release-source-toggle') && hasClass(n, 'release-source-inline') && + n.children.find(nonblank)?.name === 'summary' && + attached.slice(n.children.find(nonblank).startIndex, n.children.find(nonblank).endIndex + 1) === 'More details'; + const replacements = []; + for (const d of DomUtils.findAll(standard, nodes.children)) { + let prev = d.prev; + while (prev && !nonblank(prev)) prev = prev.prev; + if (!prev) continue; + if (prev.name === 'p') { + const end = prev.endIndex + 1 - '

'.length; + if (attached.slice(end, prev.endIndex + 1) === '

') replacements.push([end, d.startIndex, '⁠

']); + } else if (standard(prev) && hasClass(d.parent, 'oc-accordion-content')) { + const end = prev.endIndex + 1 - '
'.length; + if (attached.slice(end, prev.endIndex + 1) === '') replacements.push([end, d.children.find(nonblank).endIndex + 1, '\n']); + } + } + const joined = []; let cursor = 0; + for (const [start,end,markup] of replacements) { joined.push(attached.slice(cursor,start), markup); cursor=end; } + return joined.join('') + attached.slice(cursor); +}