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
rst2pdf
andpygments
.Then make a copy of
rst2html
, call itmyrst2html
or whatever you want.In the copy, add this after the imports:
And that's it, you now have the code-block directives.
I could make it work as follows :
To generate
<pre>..</pre>
, I needed to modify ParsedLiteral, so I copied the ParsedLiteral class into Code as follows. Changing the line 5self.options['class'] = ['brush: js;'] # <--
is the main idea.class Code(Directive):
Add one line in init.py as follows.
_directive_registry = { 'code' : ('body', 'Code'),
Now, you can use the following code
To get this HTML code
Possible Easy Solution?
I could use ParsedLiteral if I find a way to pass the parameter of 'bruch: js;'. However, when I tried the code
The tag becomes
<pre class="brunch ja">
.