1

I often have Markdown text in my clipboard that I would like to insert into an org file. After pasting the text into my org-mode file, is there a quick way to convert it to org format? For example, invoke Pandoc on a selected region/subtree?

3

You can select the pasted-in region (if you do it right after you paste it in, it should already be marked) and then run pandoc on the region with C-u M-| pandoc -f markdown -t org RET. The prefix argument says: "replace the region with the output of the command". This is a bit fragile: if you mistype, you might end up with the region erased, but you can always paste it in and try again.

  • thanks, this is exactly what I needed. @matteol answer wraps it in a function --- also quite useful. – Raj Sep 19 '20 at 16:03
1

This function executes the same command of NickD's answer, without the risk of mistype.

(defun my-md-to-org-region (start end)
  "Convert region from markdown to org"
  (interactive "r")
  (shell-command-on-region start end "pandoc -f markdown -t org" t t))
  • 1
    Indeed - both answers use shell-command-on-region, one under the covers and the other explicitly. The trade-off is between flexibility (the key sequence in my answer allows you to specify any shell command, but you have to type the command) whereas the function in this answer is safer in that you don't have to type the command but it is less flexible in that it only executes one command - you'd have to define a different function to run a different command. Which one the OP picks is very much a matter of personal choice. – NickD Sep 19 '20 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.