Repository navigation
feat(preview): show a copy icon on every code block's copy button - #1064
Merged
PathGao merged 2 commits intoNov 8, 2026
Merged
Conversation
A fenced block with a language showed only the language name, in 9 px text at 30% opacity, so the copy button read as a caption and readers did not find it. The label now always carries the copy icon, with the language name beside it, and is larger and less faint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
Code blocks in the preview already have a copy button: the label in the top-right corner. But on a block with a language, the label is just the language name (
BASH,PYTHON) in 9 px text at 30% opacity. It reads as a caption, not a button. I went looking for a copy button, didn't find one, and only learned the label was it by reading the source. This makes the button look like a button.:focus-visiblematches hover, so the label shows up when reached with the keyboard too.Clicking it works exactly as before: it copies the code and the label flashes "Copied!".
Mechanism
In
renderRichContent(src/lib/utils/richContent.ts), the label gotCOPY_ICON_SVGonly in theelsebranch, when the block had no language. With a language, it gottextContent = languageand nothing else. Now the icon is always set, and the language goes in a<span class="lang-label-name">after it.The icon has no text, so the label's
textContentis still exactly the language. The existing tests that read.lang-labeltext (preview.richContent.test.ts, the idempotence tests inpreview.spec.ts) are unchanged and still pass.flashCopiedLabelsaves and restoresinnerHTML, so the icon comes back after "Copied!".Scope
titlestays the hard-coded English "Click to copy code". Moving it to i18n would touch every locale file, and that's a separate change.@media printand the exported HTML already hide.lang-label.Tests
New
describe('copy button markup')inscripts/preview.spec.ts(vitest, real DOM). It runsrenderRichContentwith stub libraries and checks three things:.lang-label-nameholding the language, andtextContentis still the languageonCopyCodeWith the
richContent.tschange reverted and the test kept, the first test goes red, as it should (Tests 1 failed | 2 passed).Verification
On Windows 11:
Manually, in the release build on Windows 11:
bashandpythonblocks show the icon plus the language name, a plain block shows the icon alone, hover brightens it, and clicking copies the code (without the label) and flashes "Copied!".Not verified: macOS and Linux. The change is CSS and DOM only, with nothing platform-specific.
🤖 Generated with Claude Code