我知道 reStructuredText 有这个指令:
.. code:: bash
gedit pohl.m
它呈现一个代码块。有没有办法让内联片段的语法突出显示,如下所示:
Do edit the file, type ``gedit pohl.m`` into a terminal.
反引号将其标记为代码,但我想用像 block 这样的符号来突出显示它。这可能吗?
最佳答案
进一步研究后,我偶然发现了文档 reStructuredText Interpreted Text Roles 。从这个文档:
Interpreted text uses backquotes (`) around the text. An explicit role marker may optionally appear before or after the text, delimited with colons. For example:
This is `interpreted text` using the default role. This is :title:`interpreted text` using an explicit role.
好像有一个code
role ,因此您只需输入
:code:`a = b + c`
渲染内联代码块。要获得语法突出显示,您可以定义自定义角色。例如
.. role:: bash(code)
:language: bash
然后您可以像这样使用:
Here is some awesome bash code :bash:`a = b + c`.
请注意,角色定义必须放在对角色的引用之前。
请注意,我链接到的文档没有提及它所引用的 docutils 版本。代码角色在 docutils 0.8.1 中不可用(这是我必须测试的唯一版本)。
关于restructuredtext - reStructuredText 中的内联代码突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10870719/