Convert markdown to word docx with pandoc
By Peter Florijn -
If you need to convert files from one markup format into another, pandoc is your swiss-army knife.
Installation¶
My OS is OSX so the easiest is to use Homebrew.
With homebrew¶
$ brew install pandoc
Use the installer¶
Go to the github project downloads
https://github.com/jgm/pandoc/releases/
Convert your document¶
$ pandoc -o output.docx -f markdown -t docx markdown-file.md
Make it easy¶
To make it even easier I added the below code to my .bashrc file
...
# aliases
...
alias md2word=md2word # alias the function below
# functions
...
function md2word () {
PANDOC_INSTALLED=$(pandoc --version >> /dev/null; echo $?)
if [ "0" == ${PANDOC_INSTALLED} ]; then
pandoc -o $2 -f markdown -t docx $1
else
echo "Pandoc is not installed. Unable to convert document."
fi
}
Convert a file¶
md2word ~/path/to/some/markdown/file/to/convert.md ~/path/to/some/word/document/output.docx
Use Pandoc from Sublime¶
http://plaintext-productivity.net/2-05-how-to-set-up-sublime-text-for-markdown-export-to-word.html
My customized build file¶
{
"cmd": ["/usr/local/bin/pandoc", "-S", "-s", "-f", "markdown", "-t", "docx", "-o", "/Users/peter/Documents/Docs/Inbox/$file_base_name.docx", "$file_name"],
"selector": "text.html.markdown"
}