Merge pull request #162 from RaptorCZ/master

Process linebreaks and convert them to br element.
This commit is contained in:
Eric Holscher 2019-08-09 11:08:55 -07:00 committed by GitHub
commit 59dcaaab84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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()