Convert rich text on the clipboard to Markdown in OS X

osascript -e'get the clipboard as"RTF "'|sed 's/«data RTF //;s/»//'|xxd -r -p|textutil -convert html -stdin -stdout|pandoc -f html -t markdown_strict --no-wrap --atx-headers
This is useful for converting a piece of text from a browser or a PDF reader to Markdown. pbpaste -Prefer rtf no longer works for getting the rich text version of the clipboard. markdown_strict uses syntax without Pandoc extensions. --no-wrap disables hard wrapping and --atx-headers uses ATX headers instead of SETEX headers. You can also use osascript -e'get the clipboard as"HTML"'|sed 's/«data HTML//;s/»//'|xxd -r -p to get an HTML version of the clipboard which is included for text copied from a web view in applications like Safari and Chrome.

By: lri
2019-01-22 06:50:09

What Others Think

You guys are great! custom shed builders near me
geebranz · 22 weeks and 6 days ago
Wow, this command is useful in converting PDF files into markdown which is incredibly useful for students. I have copied all the steps to do so and I am pretty sure that I would do it in the right way by using this command. Now I need to visit legit service to read reviews about online writers before getting assistance from them to complete my homework about this topic.
DeniseChastain · 14 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: