From 357a732caf73f5dd99de8d0405afc1db402c0d0e Mon Sep 17 00:00:00 2001 From: Raptor Date: Sun, 30 Jun 2019 13:44:30 +0200 Subject: [PATCH] Process linebreaks and convert them to br element. --- recommonmark/parser.py | 3 +++ tests/test_basic.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/recommonmark/parser.py b/recommonmark/parser.py index cc02795..e8667db 100644 --- a/recommonmark/parser.py +++ b/recommonmark/parser.py @@ -109,6 +109,9 @@ class CommonMarkParser(parsers.Parser): def visit_softbreak(self, _): self.current_node.append(nodes.Text('\n')) + def visit_linebreak(self, _): + self.current_node.append(nodes.raw('', '
', format='html')) + def visit_paragraph(self, mdnode): p = nodes.paragraph(mdnode.literal) p.line = mdnode.sourcepos[0][0] diff --git a/tests/test_basic.py b/tests/test_basic.py index 798c395..c087062 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -459,6 +459,24 @@ class TestParsing(unittest.TestCase): """ ) + def test_linebreak(self): + self.assertParses( + """ + line1 + line2 + """, + """ + + + + line1 + <br /> + line2 + + + """ + ) + if __name__ == '__main__': unittest.main()