From 2cce30a9b55eeeddc1ed826c8a2ada53777c3eea Mon Sep 17 00:00:00 2001 From: Howard Smith Date: Thu, 3 Feb 2022 14:42:26 +0000 Subject: [PATCH] Leave trailing line break in reST directives (#385) * Add to `pdoc.test.Docformats.test_reST_include` to catch issue. * Add a single line-break at the end of `.. include::`ed files - except for when in a code block. * Minor change comment * Revert last 2 commits. * Don't consume trailing newline from reST directives. * [] itself a disjunctive list of characters --- pdoc/html_helpers.py | 6 +++++- pdoc/test/__init__.py | 17 ++++++++++++++++- pdoc/test/example_pkg/_reST_include/table.md | 3 +++ pdoc/test/example_pkg/_reST_include/test.py | 4 ++++ 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 pdoc/test/example_pkg/_reST_include/table.md diff --git a/pdoc/html_helpers.py b/pdoc/html_helpers.py index 8ba63db6..51861947 100644 --- a/pdoc/html_helpers.py +++ b/pdoc/html_helpers.py @@ -275,6 +275,9 @@ def _admonition(match, module=None, limit_types=None): if limit_types and type not in limit_types: return match.group(0) + if text is None: + text = "" + if type == 'include' and module: try: return _ToMarkdown._include_file(indent, value, @@ -323,7 +326,8 @@ def admonitions(text, module, limit_types=None): See: https://python-markdown.github.io/extensions/admonition/ """ substitute = partial(re.compile(r'^(?P *)\.\. ?(\w+)::(?: *(.*))?' - r'((?:\n(?:(?P=indent) +.*| *$))*)', re.MULTILINE).sub, + r'((?:\n(?:(?P=indent) +.*| *$))*[^\r\n])*', + re.MULTILINE).sub, partial(_ToMarkdown._admonition, module=module, limit_types=limit_types)) # Apply twice for nested (e.g. image inside warning) diff --git a/pdoc/test/__init__.py b/pdoc/test/__init__.py index 8b67ab77..c98d0c8e 100644 --- a/pdoc/test/__init__.py +++ b/pdoc/test/__init__.py @@ -1568,7 +1568,22 @@ def test_reST_include(self):

1 x = 2 x = 3 -x =

''' +x =

+ + + + + + + + + + + + + +
NameValue
HelloWorld
+

Remaining.

''' mod = pdoc.Module(pdoc.import_module( os.path.join(TESTS_BASEDIR, EXAMPLE_MODULE, '_reST_include', 'test.py'))) html = to_html(mod.docstring, module=mod) diff --git a/pdoc/test/example_pkg/_reST_include/table.md b/pdoc/test/example_pkg/_reST_include/table.md new file mode 100644 index 00000000..abf0fc4f --- /dev/null +++ b/pdoc/test/example_pkg/_reST_include/table.md @@ -0,0 +1,3 @@ +| Name | Value | +| ----- | ----- | +| Hello | World | diff --git a/pdoc/test/example_pkg/_reST_include/test.py b/pdoc/test/example_pkg/_reST_include/test.py index 96c25c41..acf75900 100644 --- a/pdoc/test/example_pkg/_reST_include/test.py +++ b/pdoc/test/example_pkg/_reST_include/test.py @@ -8,4 +8,8 @@ .. include:: foo/../_include_me.py :start-after: = :end-before: 4 + +.. include:: table.md + +Remaining. """