Skip to content

Commit b103ad4

Browse files
committed
BUG: Ensure trailing LF in markdown output (Module.text())
Compatible with markdownlint. Fixes #458 Thanks!
1 parent 1e9d179 commit b103ad4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pdoc/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,10 @@ def text(self, **kwargs) -> str:
889889
Returns the documentation for this module as plain text.
890890
"""
891891
txt = _render_template('/text.mako', module=self, **kwargs)
892-
return re.sub("\n\n\n+", "\n\n", txt)
892+
txt = re.sub("\n\n\n+", "\n\n", txt)
893+
if not txt.endswith('\n'):
894+
txt += '\n'
895+
return txt
893896

894897
def html(self, minify=True, **kwargs) -> str:
895898
"""

pdoc/test/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,10 @@ def test_mock_signature_error(self):
12001200
# GH-350 -- throws `TypeError: 'Mock' object is not subscriptable`:
12011201
self.assertIsInstance(inspect.signature(Mock(spec=lambda x: x)), inspect.Signature)
12021202

1203+
def test_ends_with_newline(self):
1204+
self.assertEqual('\n', DUMMY_PDOC_MODULE.text()[-1])
1205+
self.assertEqual('\n', DUMMY_PDOC_MODULE.html()[-1])
1206+
12031207

12041208
class HtmlHelpersTest(unittest.TestCase):
12051209
"""

0 commit comments

Comments
 (0)