If we want to convert the contents of the file code.md
into HTML, we can use the markdown2-2.7 tool with the fenced-code-blocks extension as follows:
markdown2-2.7 -x fenced-code-blocks code.md > code.html
The output HTML will look something like this:
<p>Here is our first program.</p>
<div class="codehilite"><pre><code><span class="n">s</span> <span class="o">=</span> <span class="s">"Hello, World!"</span>
<span class="k">print</span> <span class="n">s</span>
</code></pre></div>
After this conversion, it's necessary to manually add the html
, head
, and body
tags to the output. Additionally, you'll need to link a CSS stylesheet from here to enable syntax highlighting.
It makes me wonder if markdown2 is really the best choice for this process, or if there's a better way to streamline the post-processing steps without using additional scripts?
In my case, I installed markdown2
and pygments
on my Mac OS X system using the following commands:
sudo port install py27-markdown2
sudo port install py27-pygments