Skip to content

Commit

Permalink
Add visit_html_block
Browse files Browse the repository at this point in the history
Without this any html_block nodes processed by the parser are dropped.
`visit_html_block` uses the existing logic for `visit_html_inline`.

Added a test case to check html_blocks are parsed as expected.

Fixes: readthedocs#121
  • Loading branch information
Anntoin committed Oct 8, 2018
1 parent 9c15d32 commit be55a6d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
8 changes: 7 additions & 1 deletion recommonmark/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,19 @@ def visit_block_quote(self, mdnode):
self.current_node.append(q)
self.current_node = q

def visit_html_inline(self, mdnode):
def visit_html(self, mdnode):
raw_node = nodes.raw(mdnode.literal,
mdnode.literal, format='html')
if mdnode.sourcepos is not None:
raw_node.line = mdnode.sourcepos[0][0]
self.current_node.append(raw_node)

def visit_html_inline(self, mdnode):
self.visit_html(mdnode)

def visit_html_block(self, mdnode):
self.visit_html(mdnode)

def visit_thematic_break(self, _):
self.current_node.append(nodes.transition())

Expand Down
22 changes: 21 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def test_horizontal_rule(self):
"""
)

def test_html(self):
def test_html_inline(self):
self.assertParses(
"""
Foo
Expand All @@ -423,6 +423,26 @@ def test_html(self):
"""
)

def test_html_block(self):
self.assertParses(
"""
Foo
<div>
<blink>Blink</blink>
</div>
""",
"""
<?xml version="1.0" ?>
<document source="&lt;string&gt;">
<paragraph>Foo</paragraph>
<raw format="html" xml:space="preserve">&lt;div&gt;
&lt;blink&gt;Blink&lt;/blink&gt;
&lt;/div&gt;</raw>
</document>
"""
)

def test_eval(self):
self.assertParses(
"""
Expand Down

0 comments on commit be55a6d

Please sign in to comment.