62

I've got hundreds of personal notes stored as files in Markdown format, after several years using the VoodooPad personal wiki software for OS X.

There's plenty of information available for exporting from org mode to Markdown, but is there an easy way to convert Markdown to org mode format?


Update

Thanks to user2619203's answer and this answer to a question on batch processing of files with Pandoc I was able to convert four hundred Markdown files into org mode format in just a few minutes.

The solution was to export the VoodooPad document to a folder as text (File > Export Document > Export as Text...). Then call pandoc via the find command to convert them all in one go:

$ find . -name \*.txt -type f -exec pandoc  -f markdown -t org -o {}.org {} \; 

The converted .org files I've looked at are formatted beautifully -- even the codeblocks and format styling. Thank-you, user2619203.

To simply convert one file from Markdown to Org the following command can be used:

pandoc -f markdown -t org -o newfile.org original-file.markdown

Here is a link to the Pandoc documentation

1
  • Since you are using pandoc you might be interested in pandoc-mode for emacs, its pretty neat Sep 10, 2015 at 13:55

4 Answers 4

55

Pandoc can convert between multiple document formats.

To convert a bunch of Markdown files to org-mode:

for f in `ls *.md`; do 
  pandoc -f markdown -t org -o ${f}.org ${f}; 
done
4
  • 19
    Please consider adding more substance, such as a link to a relevant part of documentation, a particular pandoc command to use, a minimal working example. See How do I write a good answer?. (In its present form this is more of a comment than an answer.) Dec 17, 2014 at 2:34
  • Found the relevant documentation at johnmacfarlane.net/pandoc/README.html
    – Steve HHH
    Dec 17, 2014 at 2:44
  • 2
    Not related to pandoc, but for the shell, consider using for f in *.md instead of ls *.md for this purpose. See the great bash wiki for a detailed explanation. Jul 27, 2021 at 18:56
  • 3
    Also, using bash parameter expansion, we can remove the md extension so that the resulting files are just like "foo.org" instead of "foo.md.org": for f in *.md ; do pandoc -f markdown -t org -o "${f%%.md}".org "$f" ; done Jul 27, 2021 at 19:01
6

Here is an emacs function that will convert the current buffer's content to orgmode format using pandoc:

  (defun markdown-convert-buffer-to-org ()
    "Convert the current buffer's content from markdown to orgmode format and save it with the current buffer's file name but with .org extension."
    (interactive)
    (shell-command-on-region (point-min) (point-max)
                             (format "pandoc -f markdown -t org -o %s"
                                     (concat (file-name-sans-extension (buffer-file-name)) ".org"))))
5

Try this new cool package: org-pandoc-import.

0

A modification of the answer provided by the author that has the benefit of renaming .md files to .org, instead of to .md.org:

fd . -I --extension=md --type=f --exec bash -c 'pandoc -f markdown -t org -o "${1%.md}".org "$1"' - '{}' \;

Edit: this works by passing 'pandoc ...' to bash as a command string through bash -c, which gives more flexibility than --exec pandoc ... in terms of string processing in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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