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?