Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert rich text on the clipboard to Markdown
if encoded=`osascript -e 'the clipboard as «class HTML»'` 2>/dev/null; then echo $encoded | perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))' | pandoc --no-wrap -f HTML -t markdown; else; pbpaste; fi
# for my .vimrc:
# command PasteMarkdown :read !if encoded=`osascript -e 'the clipboard as «class HTML»'` 2>/dev/null; then echo $encoded | perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))' | pandoc --no-wrap -f HTML -t markdown; else; pbpaste; fi
# nnoremap ,pmd :PasteMarkdown<CR>
@martinmts
Copy link

martinmts commented Oct 10, 2021

Hi, thanks for sharing.
I tried the code. It returned an error initially. I removed the ; after else, and it worked great.

@rolandcrosby
Copy link
Author

rolandcrosby commented Oct 10, 2021

I see that in bash as well. I think I was using ZSH at the time I wrote this, where this syntax seems to work. Also pandoc changed its arguments and seems to prefer --wrap=none instead of --no-wrap now.

@martinmts
Copy link

martinmts commented Oct 11, 2021

Also pandoc changed its arguments and seems to prefer --wrap=none instead of --no-wrap now.
Yes. I also made the change to that after seeing the error message.

Thanks again for sharing. I spent hours and hours searching for a solution and yours is the only one that worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment