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

Steve HHH
  • 725
  • 1
  • 5
  • 7

4 Answers4

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
joncgoodwin
  • 697
  • 6
  • 3
  • 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?](http://stackoverflow.com/help/how-to-answer). (In its present form this is more of a comment than an answer.) – Constantine Dec 17 '14 at 02:34
  • Found the relevant documentation at http://johnmacfarlane.net/pandoc/README.html – Steve HHH Dec 17 '14 at 02: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](https://mywiki.wooledge.org/BashPitfalls#for_f_in_.24.28ls_.2A.mp3.29) for a detailed explanation. – Fernando Basso Jul 27 '21 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` – Fernando Basso Jul 27 '21 at 19:01
5

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"))))
user905686
  • 327
  • 2
  • 11
5

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

Leu_Grady
  • 2,420
  • 1
  • 17
  • 27
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.

harabat
  • 31
  • 5