How to convert HTML/Rich Text to Markdown in Automator


I have an Automator service that takes selected text and saves it in a file. However, bold, italics, and linked URLS aren't preserved. Is there a way I can convert it to Markdown before I save it? When I searched Google, I only found guides to convert plain text to HTML.

Best Answer

  • HTML to Markdown

    Brett Terpstra has written these automator services to help manipulate markdown in OSX.

    One of these services does convert HTML to Markdown (which answers one part of your question), and any of these services can be individually added and assigned a shortcut if you so please. I myself use Markdown to RTF to send pretty emails written in md.

    However, none of the services seem to do RTF to Markdown. And so deeper into the rabbit hole of RTF clipboard extraction I went...

    RTF to Markdown

    First I found this post and this SO question. The key, I found, is to use OSX built-in pbpaste (or osascript) and textutil.

    And so, I've written a simple RTF to Markdown service for anyone who is still looking to compliment Brett's services mentioned above, it simply converts input to HTML and pipes result to the "HTML to Markdown" service.

    Note: RTF HTML output is not always what you are looking at because of how the style is converted, so I would go with HTML to Markdown where possible.