paste clipboard as html and convert to markdown
Is your feature request related to a problem?
When I paste copied content, only plain text is pasted. I have to manually go back and add links and formatting via Markdown. This is time consuming.
Describe the solution you'd like
It would be very helpful if the "text/html" content of the clipboard is automatically converted to markdown.
I have already looked at turndown and it looks very promising
An implementation would also be very simple and I can gladly submit this as a pull request.
https://github.com/usememos/memos/blob/118254544828cfcf38851dffb40268fe5a42e52f/web/src/components/MemoEditor/index.tsx#L244
const handlePasteEvent = async (event: React.ClipboardEvent) => {
if (event.clipboardData && event.clipboardData.files.length > 0) {
event.preventDefault();
await uploadMultiFiles(event.clipboardData.files);
}
if (event.clipboardData && event.clipboardData.types.includes("text/html")) {
event.preventDefault();
const turndownService = new TurndownService();
const markdown = turndownService.turndown(event.clipboardData.getData("text/html"));
editorRef.current?.insertText(markdown);
}
};
BUT
But I have the following concerns:
- Converting from html to Markdown is not 100% perfect
- You may want to insert as plaintext after all
- you should be able to decativate this function
- Ctrl+Shift+V does not seem to work in firefox, only chromium.
The perfect solution would be a new button to insert. For example, this could look like this (red just to highlight):
The problem here, however, is that not all browsers have access to the clipboard and therefore pasting does not work. The whole thing must therefore take place in the ClipboardEvent
https://support.mozilla.org/bm/questions/1068472
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard
Possible solutions
- Every time a "text/html" is detected, a popup could be displayed asking whether the whole thing should be inserted as plaintext or html.
- The (red) insert button shown above as an example could become a checkbox / a toggeble button. This way you can activate this button and only then will the inserted content be converted.
- make it a setting in the preferences to activate / deactivate this feature
What do you think of the idea? What solution would you suggest? I would be happy to create a pull request
Additional context
No response
This issue is stale because it has been open 14 days with no activity.