Skip to content

Instantly share code, notes, and snippets.

@pa-0
Forked from rolandcrosby/gist:c26571bf4e263f695d2f
Last active January 30, 2025 04:01
Show Gist options
  • Save pa-0/c9e8f7b852fa0204d190ed5f04e13d26 to your computer and use it in GitHub Desktop.
Save pa-0/c9e8f7b852fa0204d190ed5f04e13d26 to your computer and use it in GitHub Desktop.
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 --wrap=none -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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment