diff --git a/debian/control b/debian/control --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ libjs-jquery-flot, libjs-jquery-flot-tooltip, python3-all, - python3-flask-api, + python3-docutils, python3-flask-testing, python3-nose, python3-setuptools, diff --git a/swh/web/ui/apidoc.py b/swh/web/ui/apidoc.py --- a/swh/web/ui/apidoc.py +++ b/swh/web/ui/apidoc.py @@ -143,15 +143,6 @@ 'doc': argdoc, 'default': default } - self.req_args = ['call_args', 'doc_route'] - - def check_args(self, kwargs): - missing = [arg for arg in self.req_args if arg not in kwargs] - if len(missing) > 0: - message = 'Expected keyword args %s, missing %s.' % ( - ', '.join(self.req_args), - ', '.join(missing)) - raise SWHAPIDocException(message) def __call__(self, f): @wraps(f) diff --git a/swh/web/ui/renderers.py b/swh/web/ui/renderers.py --- a/swh/web/ui/renderers.py +++ b/swh/web/ui/renderers.py @@ -6,6 +6,7 @@ import re import yaml import json +import sys from docutils.core import publish_parts from docutils.writers.html4css1 import Writer, HTMLTranslator @@ -119,13 +120,6 @@ self.body_prefix = [] self.body_suffix = [] - # disable blockquotes to ignore indentation issue with docstrings - def visit_block_quote(self, node): - pass - - def depart_block_quote(self, node): - pass - def visit_bullet_list(self, node): self.context.append((self.compact_simple, self.compact_p)) self.compact_p = None @@ -141,6 +135,31 @@ Utility function to htmlize reST-formatted documentation in browsable api. """ + + def trim(docstring): + """Correctly trim triple-quoted docstrings, taking into account + first-line indentation inconsistency. + Sourced from PEP257. + """ + if not docstring: + return '' + lines = docstring.expandtabs().splitlines() + indent = sys.maxsize + for line in lines[1:]: + stripped = line.lstrip() + if stripped: + indent = min(indent, len(line) - len(stripped)) + trimmed = [lines[0].strip()] + if indent < sys.maxsize: + for line in lines[1:]: + trimmed.append(line[indent:].rstrip()) + while trimmed and not trimmed[-1]: + trimmed.pop() + while trimmed and not trimmed[0]: + trimmed.pop(0) + return '\n'.join(trimmed) + + docstring = trim(docstring) return publish_parts(docstring, writer=DOCSTRING_WRITER)['html_body'] diff --git a/swh/web/ui/templates/api.html b/swh/web/ui/templates/api.html --- a/swh/web/ui/templates/api.html +++ b/swh/web/ui/templates/api.html @@ -5,7 +5,7 @@ {% for route, doc in doc_routes %}

{{ route }}

- {{ doc }} + {% autoescape off %}{{ doc | safe_docstring_display }}{% endautoescape %}

{% endfor %} diff --git a/swh/web/ui/templates/apidoc.html b/swh/web/ui/templates/apidoc.html --- a/swh/web/ui/templates/apidoc.html +++ b/swh/web/ui/templates/apidoc.html @@ -13,7 +13,7 @@

Request

{{ request.method }} {{ request.url }}

Result

-
 {% autoescape off %} {{ response_data | urlize_api_links }} {% endautoescape %} 
+
{% autoescape off %}{{ response_data | urlize_api_links }}{% endautoescape %}
{% endif %}
diff --git a/swh/web/ui/tests/test_renderers.py b/swh/web/ui/tests/test_renderers.py --- a/swh/web/ui/tests/test_renderers.py +++ b/swh/web/ui/tests/test_renderers.py @@ -214,9 +214,9 @@ # update api link with html links content with links docstring = """This is my list header: - - Here is item 1, with a continuation - line right here - - Here is item 2 + - Here is item 1, with a continuation + line right here + - Here is item 2 Here is something that is not part of the list"""