Generating HTML from Markdown with Pandoc
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!
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.
Pingback: Generating HTML from Markdown with Pandoc | Adv...
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
Might I recommend the use of https://github.com/ryakad/pandoc-php/ if you want to be able to access pandoc from within php instead of on the commandline ?
Thanks Scott, I use pandoc for documents rather than in applications but this is a handy tip. Thanks for sharing!