VSCode extension to copy Markdown to clipboard as rich text

Viewed 851

I am looking for an extension for Visual Studio Code that will take Markdown text and copy it to the clipboard as rich text (not HTML) so that it can be pasted into other applications while only retaining basic formatting like bold and italics. I found this extension, but it only works on Windows and I'm mostly on a Mac. I also found this post, but it's six years out of date and refers to something that appears untouched since 2004.

I'm trying to write this myself, and I'm having the same issue described in the other post: I can convert the Markdown to HTML, and I can write to the clipboard. Where I'm failing is converting the Markdown to rich text and putting that on the clipboard.

I'm using marked for Markdown to HTML, clipboardy for writing to the clipboard, and html-to-text for converting HTML to text (but I'm not sure if I need to be doing that). Here's what I'm running, with the editor text passed as text.

var result = marked(text);
var plainText = htmlToText.fromString(text, { wordwrap: false, });
clipboardy.writeSync(result);

If I pass result, I get <p><em>Test</em></p>. If I pass plainText, I get *Test*. This tells me I'm totally missing a step here, to actually convert the HTML to rich text, but I can't figure out what that is. Am I missing something obvious?

Any input or guidance would be tremendously appreciated!

0 Answers
Related