feat(markdown): copy button on fenced code blocks (LC-329) #341
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/lc-329-code-block-copy"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
A hover "Copy" button on each fenced code block in a rendered message, copying the block's raw text with a brief checkmark + "Copied" confirmation. Implements LC-329 / LC-330.
How
markdown.rs):highlight_codewraps the syntect<pre>(and the plain-text fallback) in<div class="lc-codeblock">with an icon-only<button class="lc-code-copy" data-lc-code-copy>(inline clipboard SVG). Both code-block branches get the wrapper.(body, mentions, emojis), NOT locale (the LC-290 spoiler comment is explicit). So the button carries no localized text. A delegated handler inlayout.html(locale-rendered per request, where the other global handlers live) applies the accessible name/tooltip from thecode-copy/code-copiedstrings and handles the click - copying the sibling<pre>.textContentvianavigator.clipboardwith the__lcCopyFallbackfallback, then flashing a checkmark + "Copied" for ~1.5s. It re-labels onhtmx:afterSettle/htmx:oobAfterSwap, so blocks in live-arriving/edited messages and on the wiki / search surfaces all work.main.css):.lc-codeblockrelative;.lc-code-copyabsolute top-right, revealed on hover / keyboard focus; a.lc-code-copiedstate swaps the icon for a\2713checkmark. Uses the existing theme tokens (--surface-elevated,--border,--content).code-copy/code-copiedkeys (en "Copy"/"Copied", es "Copiar"/"Copiado") rather than adding duplicates.Testing
just check(clippy standalone + saas, fmt) clean.just testandjust test-saasgreen. Newviews::markdownunit tests: a fenced block (highlighted and unknown-language fallback) getslc-codeblock+data-lc-code-copyand keeps<pre>, with no localized text baked in; a plain message gets neither. (An initial pass duplicated thecode-copyFluent keys and tripped the i18n parse tests; fixed by reusing the existing keys.)Operator impact
None. No new env var, config, or contract change; no
[operator-action]marker.🤖 Generated with Claude Code