Pasting Rich Text in Emacs

Posted on September 25, 2020

Pasting Rich text in Emacs

One of the things that I painstakingly do be it using Vim or Emacs is the extra effort I put when pasting rich text. Particularly, when I am copying text a from website that has hyperlink and I want to preserve it!

Today I spent time to remedy this situation, found this snippet on SO and had to modify/tweak it a little for it to work for me. Add it to init.el and next time you want to paste a rich text from clipboard M-x richpaste

(defun richpaste ()
  (interactive)
  (kill-new (shell-command-to-string "xclip --selection clipboard -o -t text/html | pandoc -f html -t json | pandoc -f json -t org | sed 's/ / /g'"))
  (yank))

The above code snippet will paste the rich text in org-mode format. If you want it pasted in any other format you can change the pandoc command.