Skip to content
Merged
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
4 changes: 2 additions & 2 deletions scripts/docs-site/docs-layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
3 changes: 2 additions & 1 deletion scripts/docs-site/mdx-ish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 15 additions & 4 deletions scripts/docs-site/release-inline-details.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(`<style>${css}</style><div class="docs-layout"><div class="doc">${renderMdxish(source, createMarkdownRenderer())}</div></div>`);
await page.setContent(`<style>${css}</style><div class="docs-layout"><div class="doc">${renderMdxish(shape === "list" ? source : `<AccordionGroup>\n<Accordion title="Changes">\n\n${shape === "single" ? source.split("- An unrelated")[0].slice(2).replace(/^ /gm, "") : source}\n</Accordion>\n</AccordionGroup>`, createMarkdownRenderer())}</div></div>`);
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();
Expand All @@ -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");
}
Expand All @@ -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 => `<details class="release-source-toggle release-source-inline">\n<summary>More details</summary>\n\n[#${n}](https://github.com/example/repo/pull/${n}).\n\n</details>`;
const html=renderMdxish(`<Accordion title="Topic">\n\nFinal [link](https://example.org).\n\n${record(12)}\n\n${record(34)}\n\n</Accordion>`,createMarkdownRenderer());
assert.equal(html.match(/<summary>More details/g)?.length,1);
assert.match(html,/&#8288;<\/p><details/);
for (const n of [12,34]) assert.ok(html.includes(`href="https://github.com/example/repo/pull/${n}"`));
});
55 changes: 55 additions & 0 deletions scripts/docs-site/release-point-toggles.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { DomUtils, parseDocument } from "htmlparser2";

// Component indentation normalization can split a compact disclosure from its
// Markdown bullet inside a topic accordion. Repair only that exact sibling
// shape, at render time, without changing authored Markdown or link content.
export function attachReleasePointToggles(html) {
if (!html.includes('release-source-inline')) return html;
const tree = parseDocument(html, { withStartIndices: true, withEndIndices: true });
const edits = [];
const hasClass = (node, name) => 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 - '</li>'.length;
const body = html.slice(start, end);
const paragraph = content.some(n => n.name === 'p') ? body : `<p>${body}</p>`;
edits.push([start, details.endIndex + 1, paragraph + '\n' + html.slice(details.startIndex, details.endIndex + 1) + '\n</li>\n</ul>']);
}
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) === '<summary>More details</summary>';
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 - '</p>'.length;
if (attached.slice(end, prev.endIndex + 1) === '</p>') replacements.push([end, d.startIndex, '&#8288;</p>']);
} else if (standard(prev) && hasClass(d.parent, 'oc-accordion-content')) {
const end = prev.endIndex + 1 - '</details>'.length;
if (attached.slice(end, prev.endIndex + 1) === '</details>') 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);
}
Loading