Format code blocks in docstrings

This commit is contained in:
Adam Turner 2025-01-14 12:17:46 +00:00
parent cc8161a066
commit d102e62bc7
5 changed files with 11 additions and 8 deletions

View File

@ -111,7 +111,7 @@ def module_level_function(param1, param2=None, *args, **kwargs):
{ {
'param1': param1, 'param1': param1,
'param2': param2 'param2': param2,
} }
Raises: Raises:

View File

@ -141,7 +141,7 @@ def module_level_function(param1, param2=None, *args, **kwargs):
{ {
'param1': param1, 'param1': param1,
'param2': param2 'param2': param2,
} }
Raises Raises

View File

@ -995,10 +995,11 @@ class Sphinx:
.. code-block:: python .. code-block:: python
class math(docutils.nodes.Element): pass class math(docutils.nodes.Element): ...
def visit_math_html(self, node): def visit_math_html(self, node):
self.body.append(self.starttag(node, 'math')) self.body.append(self.starttag(node, 'math'))
def depart_math_html(self, node): def depart_math_html(self, node):
self.body.append('</math>') self.body.append('</math>')
@ -1089,7 +1090,7 @@ class Sphinx:
} }
def run(self): def run(self):
... pass
def setup(app): def setup(app):
app.add_directive('my-directive', MyDirective) app.add_directive('my-directive', MyDirective)
@ -1347,8 +1348,9 @@ class Sphinx:
to them using custom roles instead of generic ones (like to them using custom roles instead of generic ones (like
:rst:role:`ref`). Example call:: :rst:role:`ref`). Example call::
app.add_crossref_type('topic', 'topic', 'single: %s', app.add_crossref_type(
docutils.nodes.emphasis) 'topic', 'topic', 'single: %s', docutils.nodes.emphasis
)
Example usage:: Example usage::
@ -1458,7 +1460,7 @@ class Sphinx:
app.add_js_file('example.js') app.add_js_file('example.js')
# => <script src="_static/example.js"></script> # => <script src="_static/example.js"></script>
app.add_js_file('example.js', loading_method="async") app.add_js_file('example.js', loading_method='async')
# => <script src="_static/example.js" async="async"></script> # => <script src="_static/example.js" async="async"></script>
app.add_js_file(None, body="var myVariable = 'foo';") app.add_js_file(None, body="var myVariable = 'foo';")

View File

@ -197,6 +197,7 @@ def cut_lines(
Use like this (e.g. in the ``setup()`` function of :file:`conf.py`):: Use like this (e.g. in the ``setup()`` function of :file:`conf.py`)::
from sphinx.ext.autodoc import cut_lines from sphinx.ext.autodoc import cut_lines
app.connect('autodoc-process-docstring', cut_lines(4, what={'module'})) app.connect('autodoc-process-docstring', cut_lines(4, what={'module'}))
This can (and should) be used in place of :confval:`automodule_skip_lines`. This can (and should) be used in place of :confval:`automodule_skip_lines`.

View File

@ -43,7 +43,7 @@ def get_lvar_names(node: ast.AST, self: ast.arg | None = None) -> list[str]:
This raises `TypeError` if the assignment does not create new variable:: This raises `TypeError` if the assignment does not create new variable::
ary[0] = 'foo' ary[0] = 'foo'
dic["bar"] = 'baz' dic['bar'] = 'baz'
# => TypeError # => TypeError
""" """
if self: if self: