Skip to content

Instantly share code, notes, and snippets.

Forked from aembleton/
Last active November 21, 2023 12:49
  • Star 69 You must be signed in to star a gist
  • Fork 19 You must be signed in to fork a gist
Star You must be signed in to star a gist
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.


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

pandoc -f docx -t markdown -o 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.

# generate a Markdown version of a word document. Goes in separate folder, since
# images are extracted and converted as well (separate folder avoids naming clashes).
# with pandoc
# --extract-media=[media folder]
# filename #(no extension)
# This will generate a converted file in a subfolder, for example if you have a file
# `contract.docx`:
# generates:
# ```
# contract
# ├──
# └── media
# ├── image1.png
# ├── image2.png
# └── image3.png
# ```
# Author: Jesper Rønn-Jensen 2015-11-30
# Inspired by
which pandoc > /dev/null
if [[ $rc != 0 ]]; then
echo "FATAL missing pandoc. You can install with 'brew install pandoc' or similar"
exit 9
if [ -z "$1" ]; then
echo "Usage:"
echo ""
echo " [filename-no-extension]"
exit 13
if [ ! -f "$1.docx" ]; then
echo "FATAL missing file '$1.docx'"
exit 11
mkdir -p "$1"
cd "$1"
pandoc -f docx -t markdown --extract-media="." -o "" "../$1.docx"
Copy link

AndreyMZ commented Apr 6, 2016

Looks like contract generates contract/ instead of contract/

Copy link

Copy link

I am an amateur in this field. Please help me out.

After doing:
sudo apt-get install pandoc

I wrote:
pandoc -f docx -t markdown -o filename.docx

And I got the message:
pandoc: Unknown reader: docx

Where am I going terribly wrong..please help

Copy link

kguidonimartins commented Dec 2, 2016

I just did change by $ in the 55 row.

Copy link

Hi @asmita-varma,

I got good results with:

pandoc -s -f markdown -t docx -o filename.docx

Converting it back, was ok, but with a few too many linefeeds and escapes than I'd like:

pandoc -s -f docx filename.docx -t markdown -o

Dean P

Copy link

Thank you @deanpeters

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