Skip to content
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

Modifiable component for code blocks #495

Open
nobkd opened this issue Feb 23, 2025 · 1 comment · May be fixed by #547
Open

Modifiable component for code blocks #495

nobkd opened this issue Feb 23, 2025 · 1 comment · May be fixed by #547
Assignees
Labels
new feature New feature or request nuekit Related to nuekit package nuemark Related to nuemark package

Comments

@nobkd
Copy link
Collaborator

nobkd commented Feb 23, 2025

I want to add a copy button to the code blocks, and would like to use a component for that. Currently, this is not possible, because a hardcoded string <pre>code block</pre> is created. It's probably possible, to add a default function to the layout components in nuemark, and if a component exists, it gets overriden.

I'll take a look, if this is easily solvable.

@nobkd nobkd added the new feature New feature or request label Feb 23, 2025
@nobkd nobkd self-assigned this Feb 23, 2025
@nobkd nobkd changed the title Modify component for code blocks Modifiable component for code blocks Feb 25, 2025
@nobkd nobkd added nuekit Related to nuekit package nuemark Related to nuemark package labels Mar 13, 2025
Harshul23 added a commit to Harshul23/nue that referenced this issue Apr 6, 2025
- Implemented a copy button functionality for code blocks to enhance user experience.
- Integrated `code-copy.js` to handle copy operations.
- Improved accessibility features for the copy button.
- Ensured proper formatting and line breaks are preserved when copying code.
- Updated relevant documentation to reflect the new feature.

Closes nuejs#495
@Harshul23
Copy link

Hi @nobkd and the team of nuejs,

I’ve implemented the feature requested in this issue to add a “Copy” button to code blocks. This new component, CodeBlockWithCopy, seamlessly integrates with our existing rendering pipeline by overriding the default code block output. It allows users to quickly copy code snippets with just hover on code block and a single click, enhancing both usability and developer experience.

  • Standards-First & Minimalism: The solution adheres to Nue’s philosophy by keeping the implementation simple and lightweight. No unnecessary abstractions were added, ensuring that every line of code is essential.
  • Modern Web Practices: It leverages the modern Clipboard API and React’s hooks to provide a smooth and responsive copy functionality.
  • Easy Integration: The component is designed to replace the built-in code block rendering with minimal changes required in the configuration (i.e., updating the component override in site.yaml).

I believe this feature not only addresses the issue effectively but also reinforces our commitment to a standards-first and brutally simple approach. I’m looking forward to your feedback and am happy to make any adjustments needed.

Here is how it looks !

Image

With a better user experience.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request nuekit Related to nuekit package nuemark Related to nuemark package
Projects
None yet
2 participants