diff --git a/autoapi/mappers/base.py b/autoapi/mappers/base.py index db439bb..06f023c 100644 --- a/autoapi/mappers/base.py +++ b/autoapi/mappers/base.py @@ -7,6 +7,7 @@ import unidecode from jinja2 import Environment, FileSystemLoader, TemplateNotFound from sphinx.util.console import darkgreen, bold from sphinx.util.osutil import ensuredir +from sphinx.util.docstrings import prepare_docstring from ..settings import API_ROOT @@ -178,6 +179,11 @@ class SphinxMapperBase(object): # lstrip_blocks=True, ) + def _wrapped_prepare(value): + return '\n'.join(prepare_docstring(value)) + + self.jinja_env.filters['prepare_docstring'] = _wrapped_prepare + self.url_root = url_root # Mapping of {filepath -> raw data} diff --git a/autoapi/templates/python/class.rst b/autoapi/templates/python/class.rst index 1f4fe4f..4e2e95d 100644 --- a/autoapi/templates/python/class.rst +++ b/autoapi/templates/python/class.rst @@ -2,8 +2,7 @@ {%- if obj.docstring %} - .. autoapi-nested-parse:: - {{ obj.docstring|indent(6) }} + {{ obj.docstring|prepare_docstring|indent(3) }} {% endif %} diff --git a/autoapi/templates/python/function.rst b/autoapi/templates/python/function.rst index e853603..8412892 100644 --- a/autoapi/templates/python/function.rst +++ b/autoapi/templates/python/function.rst @@ -3,7 +3,7 @@ .. function:: {{ obj.name }}({{ obj.args|join(',') }}) {% if obj.docstring %} - {{ obj.docstring.strip()|indent(3) }} + {{ obj.docstring|prepare_docstring|indent(3) }} {% endif %} {% endif %} \ No newline at end of file diff --git a/autoapi/templates/python/member.rst b/autoapi/templates/python/member.rst index 1f87d1f..2526660 100644 --- a/autoapi/templates/python/member.rst +++ b/autoapi/templates/python/member.rst @@ -1,4 +1,4 @@ .. {{ obj.type }}:: {{ obj.name }} - {{ obj.docstring|indent(3) }} + {{ obj.docstring|prepare_docstring|indent(3) }} diff --git a/autoapi/templates/python/method.rst b/autoapi/templates/python/method.rst index 93957e7..e49227e 100644 --- a/autoapi/templates/python/method.rst +++ b/autoapi/templates/python/method.rst @@ -1,9 +1,9 @@ {%- if obj.display %} -.. method:: {{ obj.name }}({{ obj.args[1:]|join(',') }}) +.. method:: {{ obj.short_name }}({{ obj.args[1:]|join(',') }}) {% if obj.docstring %} - {{ obj.docstring|indent(3) }} + {{ obj.docstring|prepare_docstring|indent(3) }} {% endif %} {% endif %} diff --git a/autoapi/templates/python/module.rst b/autoapi/templates/python/module.rst index 1e3f1df..40778a8 100644 --- a/autoapi/templates/python/module.rst +++ b/autoapi/templates/python/module.rst @@ -6,7 +6,7 @@ {%- if obj.docstring %} .. autoapi-nested-parse:: - {{ obj.docstring|indent(3) }} + {{ obj.docstring|prepare_docstring|indent(3) }} {% endif %} diff --git a/tests/test_integration.py b/tests/test_integration.py index 7cb4d7e..7415fb2 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -75,15 +75,15 @@ class PythonTests(LanguageIntegrationTests): example_file ) self.assertIn( - 'example.Foo.method_okay(foo=None, bar=None)', + 'method_okay(foo=None, bar=None)', example_file ) self.assertIn( - 'example.Foo.method_multiline(foo=None, bar=None, baz=None)', + 'method_multiline(foo=None, bar=None, baz=None)', example_file ) self.assertIn( - 'example.Foo.method_tricky(foo=None, bar=dict)', + 'method_tricky(foo=None, bar=dict)', example_file ) self.assertFalse(