Skip to content

feat(frontend): add copy button to rendered code blocks#271

Open
Arvuno wants to merge 1 commit into
enchant97:mainfrom
Arvuno:feat/copy-button-code-blocks
Open

feat(frontend): add copy button to rendered code blocks#271
Arvuno wants to merge 1 commit into
enchant97:mainfrom
Arvuno:feat/copy-button-code-blocks

Conversation

@Arvuno
Copy link
Copy Markdown

@Arvuno Arvuno commented Jun 3, 2026

Summary

  • Add a "Copy" button to the top-right of every fenced code block in the rendered note view.
  • Clicking the button copies the code text to the clipboard via the Clipboard API and shows a brief "Copied!" indicator.
  • Fixes (feat) Add a copy button to code blocks #170.

Testing

  • pnpm install and pnpm run wasm (requires Rust + Node 24).
  • pnpm run dev, open any note with a fenced code block, hover the block, click the button, paste to verify.
  • The button is hidden by default and fades in on hover or focus.

Notes

  • The injection is idempotent (guarded by a data-copy-button-attached attribute) and runs inside the existing render effect, so it tracks re-renders without re-attaching to stale nodes.
  • No new runtime dependencies. Styling reuses the existing Tailwind + DaisyUI tokens.
  • The Clipboard API requires a secure context; on plain HTTP the button shows "Failed" for ~1.5s. A document.execCommand('copy') fallback can be a follow-up.

Long-standing request from issue enchant97#170. Each fenced code block in the
rendered note view now has a 'Copy' button in the top-right that
copies the code text to the clipboard via the Clipboard API. The
button fades in on hover or focus and shows a 'Copied!' indicator
for ~1.5s after a successful copy.

The injection is idempotent (guarded by a data attribute) and runs
inside the existing render effect, so it tracks the existing
content re-renders without re-attaching to stale nodes. No new
runtime dependencies; the styling reuses existing Tailwind and
DaisyUI tokens.
@enchant97
Copy link
Copy Markdown
Owner

Hi, haven't had time to look at your contribution, however I just released V1 so your PR will need updating. Please also see the new contributing guide/rules.

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.

(feat) Add a copy button to code blocks

2 participants