How to Convert Rich Text in the Clipboard into Markdown?

I have solved the problem.

Got the code from here to first convert the rich text in the clipboard to html, and then use Pandoc to convert html to markdown.

Code (I believe it could be generally used for any rich text in the clipboard):

if encoded=`osascript -e 'the clipboard as «class HTML»'` 2>/dev/null; \
then echo $encoded \
    | perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))' \
    | pandoc --wrap=none -f HTML -t markdown; 
else pbpaste; 
fi

After the conversion, I added a few other action to make the text in the same format as that generated by the zotero-mdnotes extension.
The benefits are:

  1. No need for the mdnotes extenstion anymore.
    • The tutorials I have watched all use mdntoes to first create an markdown file, and then copy its content to apps such as Obsidian, and then delete the markdown file.
  2. Extremely fast. Saves time.

Macro to Download

Convert Zotfile Extracted Notes as Markdown.kmmacros (6.3 KB)

2 Likes