OvidijusParsiunas / deep-chat

Fully customizable AI chatbot component for your website
https://deepchat.dev
MIT License
1.43k stars 221 forks source link

Implement Copy Button for Code Blocks in Markdown Rendering #47

Closed 7h360df47h3r closed 10 months ago

7h360df47h3r commented 10 months ago

Summary

I'd like to propose a new feature for deep-chat: the addition of a "Copy" button to code blocks in Markdown rendering. This feature would enable users to easily copy code snippets to their clipboard, enhancing the user experience, especially for developers.

Description

Currently, when viewing code blocks in Markdown files, users have to manually select and copy code snippets. This can be cumbersome, especially for longer code blocks or when using mobile devices. By adding a "Copy" button to each code block, we can streamline this process, making it more efficient and user-friendly.

Use Case

This feature is particularly useful for developers or any users who frequently interact with code snippets in documentation, READMEs, or other Markdown files. It saves time and reduces the risk of accidentally omitting parts of the code when copying.

Suggested Implementation

A "Copy" button could be discreetly positioned in the upper right corner of each code block. Clicking the button would copy the entire content of the code block to the user's clipboard. Optionally, a brief visual confirmation (like a tooltip saying "Copied!") could appear upon successful copying.

OvidijusParsiunas commented 10 months ago

Hi. This feature has already been requested in the following issue.

In summary, the MarkDown rendering functionality is controlled by the Remarkable library and not the Deep Chat component itself, hence it is a limitation of that package. We may consider implementing markdown support ourselves or a workaround for a copy button in the future, but this is a high effort feature which has been pushed back by our current more important features.

You can alternatively add a copy button yourself by creating your own web component using this guide or Lit framework and referencing it in html responses. Or you can ofcourse build your own component locally, which is very easy if you follow these steps.

I'll be closing this issue for now and will comment if there is any further progress on this. Thanks!