15

For example:

def foo():
    '''
    .. highlight:: python
    import sys
    '''

Doesn't produce desired output (it prints the word "highlight" verbatim and doesn't format the following code in any special way). Same happens for code-block.

I tried different indentation etc. No matter what, generator succeeds with roughly the same, but not the desired output.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
wvxvw
  • 8,089
  • 10
  • 32
  • 61

1 Answers1

23

Comparing your code with the docs, you are missing indentation and an empty line between the highlight and the actual code. It should be like this:

def foo():
    '''
    .. highlight:: python
    .. code-block:: python

        import sys
        ...
    '''
Chen A.
  • 10,140
  • 3
  • 42
  • 61
  • That is not enough. The code must be in a literal block (a block where the preceding paragraph ends with `::`). – mzjn Oct 23 '17 at 15:22
  • 5
    What you have after the edit does work but is redundant. `.. highlight:: python` can be removed. – mzjn Oct 23 '17 at 15:31
  • 2
    see https://stackoverflow.com/a/50956831/1497139 for a much better explanation – Wolfgang Fahl Jan 09 '21 at 08:18