You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AssertionError from markdown2.markdown when an opening html tag is multiline, and the closing tag is on yet another line #686
As AssertionError is thrown by markdown2.markdown() when it's given a string that includes an html element where the opening tag is on multiple lines, and the closing line is on yet another line. If you remove either newline, no exception is thrown.
This is new in 2.5.5, I don't get the exception using 2.5.4.
To Reproduce
>>> markdown2.markdown('<p\n\tclass="foo">bar\n</p>')
Traceback (most recent call last):
File "<python-input-34>", line 1, in <module>
markdown2.markdown('<p\n\tclass="foo">bar\n</p>')
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/site-packages/markdown2.py", line 210, in markdown
use_file_vars=use_file_vars, cli=cli).convert(text)
~~~~~~~^^^^^^
File "/usr/local/lib/python3.14/site-packages/markdown2.py", line 504, in convert
text = self._hash_html_blocks(text, raw=True)
File "/usr/local/lib/python3.14/site-packages/markdown2.py", line 255, in inner
text = func(md, text, *args, **kwargs)
File "/usr/local/lib/python3.14/site-packages/markdown2.py", line 991, in _hash_html_blocks
text = self._strict_tag_block_sub(text, self._block_tags_a, hash_html_block_sub)
File "/usr/local/lib/python3.14/site-packages/markdown2.py", line 1120, in _strict_tag_block_sub
block = callback(block.rstrip('\n')) # remove trailing newline
File "/usr/local/lib/python3.14/site-packages/markdown2.py", line 4417, in result
return function(*args + rest, **combined)
File "/usr/local/lib/python3.14/site-packages/markdown2.py", line 927, in _hash_html_block_sub
assert m is not None
^^^^^^^^^^^^^
AssertionError
>>> markdown2.markdown('<p\n\tclass="foo">bar</p>')
'<p\n class="foo">bar</p>\n'
>>> markdown2.markdown('<p\tclass="foo">bar\n</p>')
'<p class="foo">bar\n</p>\n'
Expected behavior
No exception is thrown.
Debug info
Version of library being used:
2.5.5
Any extras being used:
none
Additional context
I'm passing pure html through markdown2.markdown() because this is coming from within a CMS that includes a markdown block as an option. Our users sometimes use the markdown block to include html snippets that they can't get on the page any other way. The snippet that triggered this for us was a script tag loading a js library to render latex math equations.
Activity
Fix trentm#686
Merge pull request #687 from Crozzers/assertionerror-issue686