如 this post 中的提问和回答,可以使用 SyntaxHighlighter漂亮的代码 list 。
借助 ReStructuredText,我可以按如下方式使用原始指令。
.. 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>
但是,我需要有可以使用的代码指令。
.. code::
function helloSyntaxHighlighter()
{
return "hi!";
}
如何将代码指令翻译成以下 HTML 代码?
<pre class="brush: js;">
function helloSyntaxHighlighter()
{
return "hi!";
}
</pre>
最佳答案
有一种方法我用过:
安装
rst2pdf
和pygments
。然后制作一份
rst2html
的副本,将其命名为myrst2html
或您想要的任何名称。在副本中,在导入之后添加:
from docutils.parsers.rst import directives import rst2pdf.pygments_code_block_directive directives.register_directive('code-block', rst2pdf.pygments_code_block_directive.code_block_directive)
就这样,您现在有了代码块指令。
关于html - 使用 ReStructuredText 获得漂亮的源代码列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4716856/