Converting clipboard HTML/rich text to Markdown

I keep notes of all kinds in a folder of plain text files that I create using a combination of nvAlt, The Archive, Keyboard Maestro, Drafts and 1Writer, with liberal doses of JavaScript, AppleScript and Shortcuts.

There’s one frequent scenario I just can’t automate well on the Mac: highlighting some text on a webpage and creating a new note using that text, formatted in markdown. I can do it by highlighting it, using a PopClip copy-to-markdown extension, and then pasting it into a note I create manually in The Archive or nvAlt — after which I can manually add the origin URL and page name. But I’d like to be able to do the whole thing in one keypress once I’ve highlight the selection.

Any suggestions? I’ve tried using KM with a shell script to invoke Pandoc, but the clipboard HTML/rich text seems to be so messy for many sites that a lot of HTML coding remains in the final markdown. I also dabbled with incorporating Brett Terpstra’s Marky API, but didn’t get very far.

I’d be willing to incorporate Python, which I know reasonably well, and/or JavaScript or JXA, which I’m starting to learn.

Ironically, I can do this super easily on my iPhone thanks to a Shortcut workflow that I adapted from something I found here. But the Mac has stymied me.

2 Likes

I am also interested in this, but just simply converting any html file to markdown.

I need to do a lot of small html pages but I like to archive in markdown to be used else if necessary.

For whole web pages, check out Brett Terpstra’s Marky, which has an API: http://heckyesmarkdown.com/