I am trying to find a solution to convert text copied from Microsoft Word on macOS to Markdown syntax when pasting in VS Code. A common use case is converting multilevel bulleted lists.

Example of what happens right now:


Instead, the desired output would be:

- Level 1
  - Level 2 a
  - Level 2 b
    - Level 3

I have tried multiple solutions which leverage CLI commands, textutil, pandoc and Applescript, but none of them work for me. I believe that Pandoc expects an MS Word file as an input, and does not seem to work with text copied from MS Word. I do not want to first save the file and then convert a whole document to Markdown; I only want to convert my clipboard to Markdown. Example commands that don't work for me:

pbpaste | textutil -convert html -stdin -stdout | pandoc -f html -t markdown | pbcopy

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

When I run osascript -e 'clipboard info', I found that the clipboard contains different classes after copying text in MS Word:

$ osascript -e 'clipboard info'
«class RTF », 43499, «class ut16», 90, «class HTML», 45214, Unicode text, 96, «class PDF », 28023, «class weba», 45520, «class utf8», 52, string, 0

Can anybody recommend a solution for my problem?

  • This looks complicated. This type of issue is one of the numerous reasons I stopped using Word absent the threat of violence. I made up some text and gave each line an 'outline level'. I don't know if this is how your text is structured. After copying to the clipboard, switched to the Finder, then Edit > Show Clipboard, which characterizes its contents as 'rich text (RTF)'. Now, as you point out, the clipboard ostensibly contains multiple classes of content so maybe 'show clipboard' is guessing which I want. Anyway, pandoc does not accept rich text as an input format. – Mockman Mar 14 at 9:08

You must log in to answer this question.

Browse other questions tagged .