-
-
Notifications
You must be signed in to change notification settings - Fork 140
feat: add copy button functionality to code blocks in README #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
| opacity: 1; | ||
| } | ||
| .readme :deep(.readme-copy-button:hover) { |
There was a problem hiding this comment.
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 🙏
server/utils/readme.ts
Outdated
| 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> |
There was a problem hiding this comment.
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
danielroe
left a comment
There was a problem hiding this 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 🙏
|
@danielroe hii! can you check now? ⟡˙⋆ |
This pull request enhances the user experience for code blocks in the
Readme.vuecomponent 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:
Readme.vueto enable copying code blocks to the clipboard and provide visual feedback by toggling between copy and success icons.Readme.vueto position and animate the copy button, making it visible on code block hover and improving its appearance.Backend rendering and sanitization:
server/utils/readme.tsto render code blocks with a copy button by default, wrapping highlighted code in a.readme-code-blockdiv and injecting a button for copy functionality.server/utils/readme.tsto supportbuttonelements and necessary attributes for the copy feature.