The Daily Scrum

Dedicated to Scrum, Agile and other stuff

Convert Markdown to Word Docx With Pandoc

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

1
$ brew install pandoc

Use the installer

Go to the github project downloads

1
https://github.com/jgm/pandoc/releases/

Convert your document

1
$ 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...

# 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

1
 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

1
2
3
4
{
    "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"
 }

Comments