Repository: lepture/mistune

Issue:
nested html links are broken with parse_block_html 
this is a variant of #81

    example_in = '<div><a href="https://example.com">Example.com</a></div>'
    mistune.markdown(example_in, escape=False, parse_block_html=True)

will generate:

    <div><a href="<a href="https://example.com"&gt;Example.com">https://example.com"&gt;Example.com</a></a></div>

if escape is toggled to True, it is also broken:

   '&lt;div&gt;&lt;a href="&lt;a href="https://example.com"&gt;Example.com"&gt;https://example.com"&gt;Example.com&lt;/a&gt;&lt;/a&gt;&lt;/div&gt;


Discussion:

Patch:
diff --git a/mistune.py b/mistune.py
index 5b05fcb..175ff01 100644
--- a/mistune.py
+++ b/mistune.py
@@ -503,7 +503,7 @@ class InlineLexer(object):
         'linebreak', 'strikethrough', 'text',
     ]
     inline_html_rules = [
-        'escape', 'autolink', 'url', 'link', 'reflink',
+        'escape', 'inline_html', 'autolink', 'url', 'link', 'reflink',
         'nolink', 'double_emphasis', 'emphasis', 'code',
         'linebreak', 'strikethrough', 'text',
     ]


Test patch:
diff --git a/tests/test_extra.py b/tests/test_extra.py
index c1d37d9..3cb9799 100644
--- a/tests/test_extra.py
+++ b/tests/test_extra.py
@@ -116,6 +116,21 @@ def test_parse_block_html():
     assert '<strong>' not in ret
 
 
+def test_parse_nested_html():
+    ret = mistune.markdown(
+        '<div><a href="http://example.org">**foo**</a></div>',
+        parse_block_html=True, escape=False
+    )
+    assert '<div><a href="http://example.org">' in ret
+    assert '<strong>' not in ret
+
+    ret = mistune.markdown(
+        '<div><a href="http://example.org">**foo**</a></div>',
+        parse_block_html=True, parse_inline_html=True, escape=False
+    )
+    assert '<div><a href="http://example.org"><strong>' in ret
+
+
 def test_trigger_more_cases():
     markdown = mistune.Markdown(
         inline=mistune.InlineLexer,