Skip to content

Commit 2cce30a

Browse files
authored
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
1 parent 4aa70de commit 2cce30a

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

pdoc/html_helpers.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ def _admonition(match, module=None, limit_types=None):
275275
if limit_types and type not in limit_types:
276276
return match.group(0)
277277

278+
if text is None:
279+
text = ""
280+
278281
if type == 'include' and module:
279282
try:
280283
return _ToMarkdown._include_file(indent, value,
@@ -323,7 +326,8 @@ def admonitions(text, module, limit_types=None):
323326
See: https://python-markdown.github.io/extensions/admonition/
324327
"""
325328
substitute = partial(re.compile(r'^(?P<indent> *)\.\. ?(\w+)::(?: *(.*))?'
326-
r'((?:\n(?:(?P=indent) +.*| *$))*)', re.MULTILINE).sub,
329+
r'((?:\n(?:(?P=indent) +.*| *$))*[^\r\n])*',
330+
re.MULTILINE).sub,
327331
partial(_ToMarkdown._admonition, module=module,
328332
limit_types=limit_types))
329333
# Apply twice for nested (e.g. image inside warning)

pdoc/test/__init__.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,22 @@ def test_reST_include(self):
15681568
<p>1
15691569
x = 2
15701570
x = 3
1571-
x =</p>'''
1571+
x =</p>
1572+
<table>
1573+
<thead>
1574+
<tr>
1575+
<th>Name</th>
1576+
<th>Value</th>
1577+
</tr>
1578+
</thead>
1579+
<tbody>
1580+
<tr>
1581+
<td>Hello</td>
1582+
<td>World</td>
1583+
</tr>
1584+
</tbody>
1585+
</table>
1586+
<p>Remaining.</p>'''
15721587
mod = pdoc.Module(pdoc.import_module(
15731588
os.path.join(TESTS_BASEDIR, EXAMPLE_MODULE, '_reST_include', 'test.py')))
15741589
html = to_html(mod.docstring, module=mod)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| Name | Value |
2+
| ----- | ----- |
3+
| Hello | World |

pdoc/test/example_pkg/_reST_include/test.py

+4
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
.. include:: foo/../_include_me.py
99
:start-after: =
1010
:end-before: 4
11+
12+
.. include:: table.md
13+
14+
Remaining.
1115
"""

0 commit comments

Comments
 (0)