Skip to content

fix(client): code-block chrome, comment cards, quote preview, and annotation anchoring#2

Merged
auspham merged 6 commits into
mainfrom
austinpham/code-block-copy-button
Jul 8, 2026
Merged

fix(client): code-block chrome, comment cards, quote preview, and annotation anchoring#2
auspham merged 6 commits into
mainfrom
austinpham/code-block-copy-button

Conversation

@auspham

@auspham auspham commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

A batch of client review-surface fixes, consolidated into one PR. Each is an independent, self-contained change with its own regression test.

  1. Borderless code blocks with Copy, and a Mermaid source view that matches them. A plain code block loses its frame and gains a Copy button; a diff keeps its framed, titled box and has no Copy button. The Mermaid "Code" toggle renders the source using the same code-block chrome - a titled MERMAID header with a Copy button and a Diagram toggle, over a line-numbered, syntax-highlighted body, on the same background - instead of a bare, differently-shaded overlay.

  2. Comment card stays on the content-column side. A comment anchored inside a narrow container (a table cell / <code> span) used to drag its rail card into the middle of the page, where it could also cover and block selection of lower content. Cards now sit at the right of the content column.

  3. An artifact's own code{border} no longer leaks into an enhanced code block. Self-styled docs commonly style every <code> (for inline snippets); that rule also matched the <code> inside the enhanced <pre>, drawing a stray 1px box around the highlighted source (visible in light mode). The enhanced block now resets border/border-radius/box-shadow on its inner code, so it owns its borderless frame regardless of the artifact's styling. Inline code is untouched.

  4. A comment-card quote previews two full lines instead of a clipped one. The rail card quote clamps to two lines, but a fixed max-height shorter than two lines cut the second line mid-glyph. An explicit line-height and a two-line max-height make the clamp and the height cap agree.

  5. Annotation selector is anchored so highlighting works on nested inline elements. cssPath emitted an unrooted selector (e.g. div:nth-of-type(1) > ul > li:nth-of-type(2) > strong); when an earlier subtree shared that tag/nth-of-type skeleton, document.querySelector resolved to the wrong element, the text guard failed, and the selection menu was force-closed. Some lines (an id-less nested <strong>, a link) silently could not be highlighted or commented on. The path is now rooted at an ancestor id, else <body>, and climbs the full chain.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor or tooling
  • Other:

How was this tested?

New browser regression tests for each behavior change (borderless/Copy/diff, the Mermaid Code view chrome + open/close model, artifact-code{border} leak, comment-card placement + stacked-card blocking, long-quote two-line preview, and the selector-collision highlight). Each fails before its fix and passes after.

  • python -m pytest tests/python (45 passed)
  • ruff check skills/htmlit tests/python (clean)
  • npm test (browser client - 26 passed)

Checklist

  • I added or updated tests for this change (a bug fix has a test that fails before the fix).
  • I did not add any runtime dependency to the skill (standard library only).
  • I did not commit vendored assets (Mermaid, highlight.js, Idiomorph).
  • Commits follow Conventional Commits and are signed off (git commit -s).

auspham added 5 commits July 8, 2026 20:21
…d source

Code rendering gets a cleaner, more useful chrome:

- A plain code block loses its outer border/frame; its header is now just the
  language name on the left and a Copy button on the right, over the pinned
  line-number gutter. Copy grabs the block's source.
- The Mermaid Code toggle shows the source as a real code block - line numbers, a
  Copy button, and Mermaid syntax highlighting (highlight.js ships no Mermaid
  language, so a small grammar is registered on first use) - instead of a bare pre.
- A diff keeps its framed box and Unified/Split header and gets no Copy button.

Shared helpers (copyText moved to util.js; makeCopyButton / makeLinenos /
lineCount / highlightMermaidSource in a new codeblock.js) keep render.js and
diagram.js from duplicating the button, gutter and highlighting. Adds a fixture
and browser tests covering the code/diff copy behaviour and the Mermaid source
view (line numbers, Copy, and highlighting).
…page

A comment anchored inside a narrow container - a table cell, a grid card, or a
<code> span - dragged its rail card into the middle of the page, because the card
hugged the immediate container's right edge. anchorRight now returns the right
edge of the widest block-level ancestor (the content column) rather than the
narrow container, so the card sits on the side as intended, wherever the comment
lands. Adds a fixture and a browser test (fails before, passes after).

Signed-off-by: Austin (Ngoc Thang) Pham <austinpham@microsoft.com>
…de blocks

A self-styled artifact often styles every <code> (e.g. "code{border:1px
solid var(--border)}" for inline snippets). That rule also matches the <code>
inside the <pre> that htmlit enhances, so a stray 1px box was drawn around the
highlighted source - visible in light mode, where it did not blend into the
dark frame.

The enhancement already resets the inner <pre> (border/background/radius) but
the sibling reset for <pre>>code only cleared background and padding. Extend it
to also zero border, border-radius and box-shadow so the enhanced block owns its
own borderless frame regardless of the artifact's generic code styling. Inline
code outside the block is untouched.

Adds a regression fixture whose artifact sets code{border} and a test asserting
the enhanced block's <code> has no border while inline code keeps its own.

Signed-off-by: Austin (Ngoc Thang) Pham <austinpham@microsoft.com>
The rail card's quote (.card-q) clamps to two lines with -webkit-line-clamp,
but a fixed max-height of 34px was shorter than two lines at the inherited
line-height, so the second line was cut mid-glyph (a faded half-line) instead
of a clean ellipsis.

Pin an explicit line-height and size max-height to exactly two lines
(calc(3em + 6px)), so the clamp and the height cap agree and a long quote
previews two whole lines.

Adds a regression test with a long quote asserting the preview is ~2 lines,
not the clipped ~1.5 it was before.

Signed-off-by: Austin (Ngoc Thang) Pham <austinpham@microsoft.com>
…ed inline elements

cssPath emitted an unrooted selector (e.g. "div:nth-of-type(1) > ul >
li:nth-of-type(2) > strong"). document.querySelector matches such a path
against any subtree at any depth, so when an earlier element shared the same
tag/nth-of-type skeleton (e.g. a <strong> nested in a card grid) it resolved to
that decoy instead of the intended element.

resolveRange's text guard then failed, pendingRects returned empty, and
openSelMenu called clearPending - closing the annotation menu and wiping the
selection. The result was that some lines (a <strong> inside a list, a link, any
id-less nested inline element) silently could not be highlighted or commented on.

Root the path at an ancestor id, otherwise <body>, and climb the full ancestor
chain instead of capping at six segments, so it always resolves absolutely to
the correct element.

Adds a browser regression test whose fixture reproduces the colliding skeleton;
it fails (menu display:none) before the fix and passes (flex) after.

Signed-off-by: Austin (Ngoc Thang) Pham <austinpham@microsoft.com>
@auspham auspham changed the title feat(client): code-block Copy + highlighted Mermaid source; fix mid-page comment cards fix(client): code-block chrome, comment cards, quote preview, and annotation anchoring Jul 8, 2026
The diagram source view was a bare overlay (no title, a lighter #f6f8fa
background, floating Copy and toggle buttons) that did not match an enhanced
code block. Rebuild it from the same pieces: a titled "MERMAID" header with the
Copy button and a "Diagram" toggle, over the line-numbered, highlighted body,
reusing the .htmlit-code / .htmlit-code-hd / .htmlit-code-body classes so it
shares the borderless chrome and background.

The diagram view keeps a floating "Code" button that opens the overlay and hides
while it is open; the header's "Diagram" button restores the diagram. The header
is sticky and opaque so the title/actions stay put while the source scrolls.

Updates the Mermaid code-view and diagram robustness tests for the new
open/close model and asserts the title, matching background and toggle.

Signed-off-by: Austin (Ngoc Thang) Pham <austinpham@microsoft.com>
@auspham auspham merged commit fb78bf4 into main Jul 8, 2026
4 checks passed
@auspham auspham deleted the austinpham/code-block-copy-button branch July 8, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant