Going From Markdown to Word Processor

by: Scott Nesbitt | 04 June 2018

One argument that I keep hearing from people is that they can’t use plain text or Markdown because they need to produce formatted word processor documents — documents created with Microsoft Word or LibreOffice Writer. An interesting argument, but not one I buy.

Why? With Markdown, you can generate a word processor document. Well, with a little help from a tool called Pandoc.

As I discussed in a previous article in this space, Pandoc is a very powerful utility that can convert between various markup languages. It also has some extensions to Markdown, which makes it quite useful for converting Markdown to a word processor format.

Now the important reminder: Pandoc is a command line application with a large number of options. But don’t let that intimidate you. I use Pandoc a lot and only touch a half dozen or so of those options at the most.

Anyway, for what I’m going demonstrate, you just need to remember a few commands.

Creating a Simple Word Processor File

Let’s assume you have a Markdown file that you want to convert to a LibreOffice Writer file. Open a terminal window, navigate to the directory in which the Markdown file resides, and then type:

pandoc -o filename.odt filename.md

Where filename is the name of your document.

If you want to create a Word file instead, change the extension .docx to .odt.

Simple, but effective.

Going a Step Beyond

The file that Pandoc spits out looks OK. It’s a tad bland, though. What if you need to have your documents with a certain look and feel? Pandoc can help, but it takes a little bit of setup.

Here’s what to do. At least under Linux. I don’t do Windows, so I can’t help you there. These instructions should work with MacOS, though.

First, run this command:

pandoc --print-default-data-file reference.odt > custom-reference.odt

That command creates a LibreOffice Writer file called custom-reference.odt which contains the styles Pandoc uses. If you use Word, change the .odt in the command to .docx. Then, move the file to a folder somewhere in your /home directory.

As I mentioned a few paragraphs ago, Pandoc’s stock word processor output is bland. Why not customize it a bit? Open the file custom-reference.odt in a word processor and:

Do whatever you want to spice up the look of your document. I’m not going to explain how to do that here. Check your word processor’s help if you need guidance. There are also good tutorials online, which you can find with your favourite search engine.

Now you’re ready use the custom-reference.odt file. To do that, run this command:

pandoc -t odt filename.md -o filename.odt --custom-reference [path-to]/custom-reference.odt

Here’s what this article looks like, converted to a LibreOffice Writer document:

A Markdown file converted to ODT

There’s a lot more I can do to tweak the output, but that works well enough. And it looks better than the stock output from Pandoc. All it took was a bit of tweaking.