As is asked and answered in this post, one can use SyntaxHighlighter for pretty code listing.
With ReStructuredText, I can use raw directive as follows.
.. raw:: html
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js"></script>
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.all();</script>
I could use `SyntaxHighlighter <http://alexgorbatchev.com/SyntaxHighlighter/>`_ for highlighting source code.
.. raw:: html
<pre class="brush: js;">
function helloSyntaxHighlighter()
{
return "hi!";
}
</pre>
However, I need to have code directive that I can use.
.. code::
function helloSyntaxHighlighter()
{
return "hi!";
}
How can I translate code directive into the following HTML code?
<pre class="brush: js;">
function helloSyntaxHighlighter()
{
return "hi!";
}
</pre>
There is a way I have used:
Install
rst2pdfandpygments.Then make a copy of
rst2html, call itmyrst2htmlor whatever you want.In the copy, add this after the imports:
And that’s it, you now have the code-block directives.