如何在Sphinx中使用reStructuredText突出显示diff输出文本?

5

我试图寻找但失败了。

我认为将以“+”开头的行标记为红色,

以“-”开头的行标记为蓝色,

就足够了。

hello.c::

    +#else                                 <<<<< want this line in red
     ISR_RESULT ISRs(U32 Interrupt, U32 Vector)
    +#endif                                <<<<< want this line in red
     {
    -//     printf ("Get IRQs \r\n");      <<<<< want this line in blue
    -       switch (Interrupt)             <<<<< want this line in blue
    -       {                              <<<<< want this line in blue
    -         case ISR_MBOX0:              <<<<< want this line in blue

请包含一个代码示例。另请参阅 diff lexers for pygments 列表,这些语言被 Sphinx 用作语言。 - Steve Piercy
我按照Steve的建议重写了代码示例。但是Steve指出的文档并没有帮助到我,我从中找不到任何提示... - Jumogehn
1
首先演示您想要进行差异比较的代码。您本地的测试是否与演示相似?如果是的话,那么要更改默认高亮显示的样式,您需要在主题的CSS文件中应用自定义样式。 - Steve Piercy
谢谢你,Steve!但是对我来说并不那么简单......不过感谢你提供演示服务的URL。 - Jumogehn
@Jeonghum,你的*.rst文件实际上是什么样子的? - sinoroc
@sinoroc,我已经编辑了我的原始问题。谢谢! - Jumogehn
1个回答

7
你应该使用 code-block 指令 并且使用 Pygmentdiff 词法分析器。你的 *.rst 文件应该类似于以下内容:
.. code-block:: diff

    +#else
     ISR_RESULT ISRs(U32 Interrupt, U32 Vector)
    +#endif
     {
    -//     printf ("Get IRQs \r\n");
    -       switch (Interrupt)
    -       {
    -         case ISR_MBOX0:

1
我忘了说谢谢!这是一个百分之百完美的答案! - Jumogehn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接