Skip to content

regression with markdown-in-html #565

@parmentelat

Description

@parmentelat

Describe the bug

I am currently facing a crash of markdown2 that results in this stack dump

Traceback (most recent call last):
  File "/<snip>/r2lab.inria.fr/md/views.py", line 565, in markdown_page
    html = markdown_module.markdown(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<snip>/r2lab.inria.fr/lib/python3.12/site-packages/markdown2.py", line 177, in markdown
    use_file_vars=use_file_vars, cli=cli).convert(text)
                                          ^^^^^^^^^^^^^
  File "/<snip>/r2lab.inria.fr/lib/python3.12/site-packages/markdown2.py", line 390, in convert
    text = self._do_markdown_in_html(text)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<snip>/r2lab.inria.fr/lib/python3.12/site-packages/markdown2.py", line 987, in _do_markdown_in_html
    return self._strict_tag_block_sub(text, self._block_tags_a, callback, True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<snip>/r2lab.inria.fr/lib/python3.12/site-packages/markdown2.py", line 967, in _strict_tag_block_sub
    block = callback(block.rstrip('\n'))  # remove trailing newline
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<snip>/r2lab.inria.fr/lib/python3.12/site-packages/markdown2.py", line 983, in callback
    block = self._hash_html_block_sub(block)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<snip>/r2lab.inria.fr/lib/python3.12/site-packages/markdown2.py", line 794, in _hash_html_block_sub
    tag = tag or re.match(r'^<(\S).*?>', html).group(1)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'group'

To Reproduce
I am yet to find out the location in my - rather large - input file that causes the issue - will try to report here if I can come up with something decently small

Expected behavior
ideally, it would be great if

  • the call would not terminate so abruptly, and would return some - possibly degraded - html
  • there was some way to pinpoint where in the file (like line/col number, or any other hint) the problem actually triggered

Debug info
this is with 2.4.12; with 2.4.11 there is no crash

Any extras being used:

yes, a few, markdown-in-html being one, and if I take it out the problem disappears, of course

Additional context

for the record, the same input has been working fine for years, and has recently -not sure with which version exactly - started to misbehave, i.e. some markdown in html that used to be interpreted as markdown have ceased to be, and so show up like this e.g.
image

this is clearly a separate issue, but it appears that the markdown-in-html thing has recently gone through changes that are breaking things for us

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions