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.
Literal code blocks (ref) are introduced by ending a paragraph with the special marker :: . The literal block must be indented (and, like all paragraphs, separated from the surrounding ones by blank lines): This is a normal text paragraph.
The Sphinx docstring formatA pair of :param: and :type: directive options must be used for each parameter we wish to document. The :raises: option is used to describe any errors that are raised by the code, while the :return: and :rtype: options are used to describe any values returned by our code.
For a function, its docstrings should consist of three essential components: a one-sentence summary, parameters (name, type, explanation, and the default value if set), and the return value (type and explanation). If the function can raise exceptions, it should be specified too.
A Python program is constructed from code blocks. A block is a piece of Python program text that is executed as a unit. The following are blocks: a module, a function body, and a class definition. Each command typed interactively is a block.
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
...
'''
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With