Skip to content

Conversation

@imrofayel
Copy link

This pull request enhances the user experience for code blocks in the Readme.vue component by adding a copy-to-clipboard feature with visual feedback. The changes include frontend event handling, UI improvements for code block interactions, and backend support for rendering copy buttons in code blocks.

Frontend functionality and UI improvements:

  • Added a click event handler in Readme.vue to enable copying code blocks to the clipboard and provide visual feedback by toggling between copy and success icons.
  • Updated CSS styles in Readme.vue to position and animate the copy button, making it visible on code block hover and improving its appearance.

Backend rendering and sanitization:

  • Modified server/utils/readme.ts to render code blocks with a copy button by default, wrapping highlighted code in a .readme-code-block div and injecting a button for copy functionality.
  • Updated the list of allowed HTML tags and attributes in server/utils/readme.ts to support button elements and necessary attributes for the copy feature.

@vercel
Copy link

vercel bot commented Feb 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Feb 1, 2026 2:00pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Feb 1, 2026 2:00pm
npmx-lunaria Ignored Ignored Feb 1, 2026 2:00pm

Request Review

opacity: 1;
}
.readme :deep(.readme-copy-button:hover) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should also be visible when focused 🙏

const html = highlightCodeSync(shiki, text, lang || 'text')
// Add copy button
return `<div class="readme-code-block" dir="ltr">
<button type="button" class="readme-copy-button" title="Copy code" check-icon="i-carbon:checkmark" copy-icon="i-carbon:copy" data-copy>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need accessible text as well

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you - this looks amazing!

I left some comments for a11y, and I think we'll also need to bump the readme cache key 🙏

@imrofayel
Copy link
Author

@danielroe hii! can you check now? ⟡˙⋆

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.

2 participants