Process linebreaks and convert them to br element.

This commit is contained in:
Raptor 2019-06-30 13:44:30 +02:00
parent cbcfbff243
commit 357a732caf
2 changed files with 21 additions and 0 deletions

View file

@ -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('', '<br />', format='html'))
def visit_paragraph(self, mdnode):
p = nodes.paragraph(mdnode.literal)
p.line = mdnode.sourcepos[0][0]

View file

@ -459,6 +459,24 @@ class TestParsing(unittest.TestCase):
"""
)
def test_linebreak(self):
self.assertParses(
"""
line1
line2
""",
"""
<?xml version="1.0" ?>
<document source="&lt;string&gt;">
<paragraph>
line1
<raw format="html" xml:space="preserve">&lt;br /&gt;</raw>
line2
</paragraph>
</document>
"""
)
if __name__ == '__main__':
unittest.main()