Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Convert a Word Document into MD

Converting a Word Document to Markdown in One Move

The Problem

A lot of important government documents are created and saved in Microsoft Word (*.docx). But Microsoft Word is a proprietary format, and it's not really useful for presenting documents on the web. So, I wanted to find a way to convert a .docx file into markdown.

Installing Pandoc

On a mac you can use homebrew by running the command brew install pandoc.

The Solution

As it turns out, there are several open-source tools that allow for conversion between file types. Pandoc is one of them, and it's powerful. In fact, pandoc's website says "If you need to convert files from one markup format into another, pandoc is your swiss-army knife." Pandoc can convert from markdown into .docx, and it also works in the other direction.

Example

Say you have the Council Rules in a Word Document named "test.docx." (For a real-life example, visit http://github.com/vzvenyach/Council_Rules/). Now, you run the following at the command line:

pandoc -f docx -t markdown -o test.md test.docx

Out is a beautiful markdown file. Admittedly, there's a bit of junk at the top with the Table of Contents. I deleted this when I rendered it nicely with strapdown.js. In the end, here's my nicely rendered version of the Rules.

Pandoc link is dead. I've forked and updated it at my own gist

I took your excellent idea, and created a bash file which also extracts images. Awesome for a one-time conversion of word documents :)

See https://gist.github.com/jesperronn/ff5764274b3642bc7f2f

I'm embarrassed to admit I love being able to convert word docs to md docs. But love this tool and hope it continues in some form.

sean-d commented Dec 15, 2016

saved me some time; I did not know pandoc supported this converstion. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment