Repository: trentm/python-markdown2 (language: python)

Issue:
bug/feature html tags wrapped in paragraph tags
**Describe the bug**

html tags are being wrapped in `<p>` in a similar fashion to https://daringfireball.net/projects/markdown/


**To Reproduce**

problem.md

    <html>
  
    <!-- Comment please ignore -->
  
    <!-- Multi
    line Comment 
    please ignore -->
  
  
    <body>
    content here
  
     <img src="some_img.jpg" alt="there is supposed to be an image here" width="500" height="600"> 
  
    Now some bullets:
  
      * one
      * two
  
    </body>
  
  
    </html>

Output

NOTE html, body, and img tags:

    <p><html></p>

    <!-- Comment please ignore -->

    <!-- Multi
    line Comment 
    please ignore -->

    <p><body>
    content here</p>

    <p><img src="some_img.jpg" alt="there is supposed to be an image here" width="500" height="600"> </p>

    <p>Now some bullets:</p>

    <ul>
    <li>one</li>
    <li>two</li>
    </ul>

    <p></body></p>

    <p></html></p>


**Expected behavior**

I'm seeking clarity on this from project readme in https://github.com/trentm/python-markdown2/blob/ac7fd196e2d8854e2f0f85c7b3c82462d83b7af1/README.md?plain=1#L11

> It 
> was written to closely match the behaviour of the original Perl-implemented
> Markdown.pl.

I was NOT expecting to see `<p>` tags around html, body. I have a larger example where it adds them around comments AND style tags.

**Debug info**
Version of library being used:

    __version_info__ = (2, 4, 14)

Any extras being used: NONE

**Additional context**

Other implementations generate what I consider sane html BUT differ from Daring Fireball 2004 Perl version (which is known to have odd issues).

I've not attempted to debug. Curious what thoughts are on this. Thanks!


bug/feature html tags wrapped in paragraph tags
**Describe the bug**

html tags are being wrapped in `<p>` in a similar fashion to https://daringfireball.net/projects/markdown/


**To Reproduce**

problem.md

    <html>
  
    <!-- Comment please ignore -->
  
    <!-- Multi
    line Comment 
    please ignore -->
  
  
    <body>
    content here
  
     <img src="some_img.jpg" alt="there is supposed to be an image here" width="500" height="600"> 
  
    Now some bullets:
  
      * one
      * two
  
    </body>
  
  
    </html>

Output

NOTE html, body, and img tags:

    <p><html></p>

    <!-- Comment please ignore -->

    <!-- Multi
    line Comment 
    please ignore -->

    <p><body>
    content here</p>

    <p><img src="some_img.jpg" alt="there is supposed to be an image here" width="500" height="600"> </p>

    <p>Now some bullets:</p>

    <ul>
    <li>one</li>
    <li>two</li>
    </ul>

    <p></body></p>

    <p></html></p>


**Expected behavior**

I'm seeking clarity on this from project readme in https://github.com/trentm/python-markdown2/blob/ac7fd196e2d8854e2f0f85c7b3c82462d83b7af1/README.md?plain=1#L11

> It 
> was written to closely match the behaviour of the original Perl-implemented
> Markdown.pl.

I was NOT expecting to see `<p>` tags around html, body. I have a larger example where it adds them around comments AND style tags.

**Debug info**
Version of library being used:

    __version_info__ = (2, 4, 14)

Any extras being used: NONE

**Additional context**

Other implementations generate what I consider sane html BUT differ from Daring Fireball 2004 Perl version (which is known to have odd issues).

I've not attempted to debug. Curious what thoughts are on this. Thanks!




Discussion / hints:
Looks like you left most of the default text in this issue. So not sure what issue you're seeing. Maybe close and reopen with clearer info.
@nicholasserra looks like I missed off indentation in the first markdown snippet. Corrected. Hopefully that's more clear now.
@nicholasserra I can't reopen this. Did you mean I should open a new issue?

Looks like you left most of the default text in this issue. So not sure what issue you're seeing. Maybe close and reopen with clearer info.
@nicholasserra looks like I missed off indentation in the first markdown snippet. Corrected. Hopefully that's more clear now.
@nicholasserra I can't reopen this. Did you mean I should open a new issue?


Fix patch:
diff --git a/CHANGES.md b/CHANGES.md
index 7049ab49..a47d7ebb 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -9,6 +9,7 @@
 - [pull #570] Fix syntax warnings in test suite
 - [pull #572] Process inline tags as HTML blocks when they span multiple lines (#571)
 - [pull #573] Add new LaTeX Extra
+- [pull #576] Fix `html`, `head` and `body` tags being wrapped in `<p>` tags (#575)
 
 
 ## python-markdown2 2.4.13
diff --git a/lib/markdown2.py b/lib/markdown2.py
index 42a1518c..86876ab5 100755
--- a/lib/markdown2.py
+++ b/lib/markdown2.py
@@ -814,7 +814,7 @@ def _detab(self, text):
     # _block_tags_b.  This way html5 tags are easy to keep track of.
     _html5tags = '|article|aside|header|hgroup|footer|nav|section|figure|figcaption'
 
-    _block_tags_a = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del|style'
+    _block_tags_a = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del|style|html|head|body'
     _block_tags_a += _html5tags
 
     _strict_tag_block_re = re.compile(r"""
@@ -2773,7 +2773,7 @@ class Latex(Extra):
 
     _single_dollar_re = re.compile(r'(?<!\$)\$(?!\$)(.*?)\$')
     _double_dollar_re = re.compile(r'\$\$(.*?)\$\$', re.DOTALL)
-    
+
     # Ways to escape
     _pre_code_block_re = re.compile(r"<pre>(.*?)</pre>", re.DOTALL) # Wraped in <pre>
     _triple_re = re.compile(r'```(.*?)```', re.DOTALL) # Wrapped in a code block ```


Test patch:
diff --git a/test/tm-cases/block_tags.html b/test/tm-cases/block_tags.html
new file mode 100644
index 00000000..12ced98a
--- /dev/null
+++ b/test/tm-cases/block_tags.html
@@ -0,0 +1,23 @@
+<html>
+
+<!-- Comment please ignore -->
+
+<!-- Multi
+line Comment
+please ignore -->
+
+
+<body>
+content here
+
+ <img src="some_img.jpg" alt="there is supposed to be an image here" width="500" height="600">
+
+Now some bullets:
+
+  * one
+  * two
+
+</body>
+
+
+</html>
diff --git a/test/tm-cases/block_tags.text b/test/tm-cases/block_tags.text
new file mode 100644
index 00000000..12ced98a
--- /dev/null
+++ b/test/tm-cases/block_tags.text
@@ -0,0 +1,23 @@
+<html>
+
+<!-- Comment please ignore -->
+
+<!-- Multi
+line Comment
+please ignore -->
+
+
+<body>
+content here
+
+ <img src="some_img.jpg" alt="there is supposed to be an image here" width="500" height="600">
+
+Now some bullets:
+
+  * one
+  * two
+
+</body>
+
+
+</html>