Generating HTML from Markdown with Pandoc

I’m writing more and more things that are not code these days, and my content-managing toolchains are becoming more developed all the time. I’ve written in REstructured Text, Asciidoc, and LaTeX, and today I’m working on an article which eventually wants to be HTML but I’m creating in Markdown because it’s much easier.

My swiss army knife of document formats is a program called pandoc. It’s absolutely fabulous, powerful, and not too complicated if you don’t need to do anything too complicated. It will guess input and output formats from file extensions, or you can be more specific if you need to. Today’s command looks like this:

pandoc article.md -o article.html

You won’t be surprised to hear that this command takes a file called article.md which contains my markdown, and outputs a file called article.html containing the HTML. I also use this to convert between all the various text markups, HTML, but also PDF and office document formats – it’s a very comprehensive tool!

7 thoughts on “Generating HTML from Markdown with Pandoc

  1. When would you ever want to generate a HTML file from Markdown? I love the format too but whenever I use it myself I always want to decorate it some way, using static site generators, CMSes or some other type of web platform. It’s always a piece of content in a wider context.

    So it’d be interesting to hear your use case with that HTML file. :)

    • I’m writing for an online outlet so they want the content in HTML, which goes into their wordpress and gets styled appropriately. I also blog in HTML myself, so while I don’t usually use Markdown and tranform it, I could do so.

  2. Pingback: Generating HTML from Markdown with Pandoc | Adv...

  3. Hi,

    I am curious about your thoughts on using command line tools via PHP, i.e. security risks and the correctness of doing so. I have always looked for native PHP libraries but recently I have started using more command line tools via php but I feel it is “wrong” if you get what I am saying…

    Thanks,

    Tim

    • This is a really good question and I don’t have much of an answer. I use many command-line tools, but basically all of them from the command-line! Providing you sanitise your inputs really well though, there’s no reason you shouldn’t shell out to the operating system from PHP IMO

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.