Merge pull request #89 from rtfd/fix-docstring-whitespace

Implement prepare_docstring filter that wraps Sphinx's
pull/90/head
Eric Holscher 8 years ago committed by GitHub
commit b6ae837be9

@ -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}

@ -2,8 +2,7 @@
{%- if obj.docstring %}
.. autoapi-nested-parse::
{{ obj.docstring|indent(6) }}
{{ obj.docstring|prepare_docstring|indent(3) }}
{% endif %}

@ -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 %}

@ -1,4 +1,4 @@
.. {{ obj.type }}:: {{ obj.name }}
{{ obj.docstring|indent(3) }}
{{ obj.docstring|prepare_docstring|indent(3) }}

@ -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 %}

@ -6,7 +6,7 @@
{%- if obj.docstring %}
.. autoapi-nested-parse::
{{ obj.docstring|indent(3) }}
{{ obj.docstring|prepare_docstring|indent(3) }}
{% endif %}

@ -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(

Loading…
Cancel
Save