Skip to content

Leave trailing line break in reST directives #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pdoc/html_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<indent> *)\.\. ?(\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)
Expand Down
17 changes: 16 additions & 1 deletion pdoc/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,22 @@ def test_reST_include(self):
<p>1
x = 2
x = 3
x =</p>'''
x =</p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Hello</td>
<td>World</td>
</tr>
</tbody>
</table>
<p>Remaining.</p>'''
mod = pdoc.Module(pdoc.import_module(
os.path.join(TESTS_BASEDIR, EXAMPLE_MODULE, '_reST_include', 'test.py')))
html = to_html(mod.docstring, module=mod)
Expand Down
3 changes: 3 additions & 0 deletions pdoc/test/example_pkg/_reST_include/table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
| Name | Value |
| ----- | ----- |
| Hello | World |
4 changes: 4 additions & 0 deletions pdoc/test/example_pkg/_reST_include/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
.. include:: foo/../_include_me.py
:start-after: =
:end-before: 4

.. include:: table.md

Remaining.
"""