Search code examples
diffhighlightrestructuredtext

How can I highlight diff output text in restructuredtext in sphinx?


I tried to find but failed.

I think coloring of lines that start with '+' in red

... and coloring of lines that start with '-' in blue

... would be enough.

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

Solution

  • You probably should use the code-block directive and use Pygment's diff lexer. Your *.rst file should probably look like this:

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