Skip to content

FancyLists: KeyError when the list number is missing #2575

@renfeisong

Description

@renfeisong

Description

With FancyLists, when the list number is missing (but the . or ) is present), parsing will throw a KeyError. Example inputs:

1. foo
. bar
1) foo
) bar

Error:

% python3 test.py
Traceback (most recent call last):
  File "/Users/USER/Downloads/test.py", line 5, in <module>
    html = markdown.markdown("1. foo\n. bar", extensions=["pymdownx.fancylists", "pymdownx.saneheaders"])
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/markdown/core.py", line 482, in markdown
    return md.convert(text)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/markdown/core.py", line 357, in convert
    root = self.parser.parseDocument(self.lines).getroot()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/markdown/blockparser.py", line 117, in parseDocument
    self.parseChunk(self.root, '\n'.join(lines))
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/markdown/blockparser.py", line 136, in parseChunk
    self.parseBlocks(parent, text.split('\n\n'))
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/markdown/blockparser.py", line 158, in parseBlocks
    if processor.run(parent, blocks) is not False:
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pymdownx/fancylists.py", line 214, in run
    attrib = {'type': self.OL_TYPES[fancy_type], '__fancylist': fancy_type}
KeyError: 'dot-'

Minimal Reproduction

#!/usr/bin/env python3

import markdown

html = markdown.markdown("1. foo\n. bar", extensions=["pymdownx.fancylists", "pymdownx.saneheaders"])
print(html)  # KeyError: 'dot-'

html = markdown.markdown("1) foo\n) bar", extensions=["pymdownx.fancylists", "pymdownx.saneheaders"])
print(html)  # KeyError: 'paren-'

Version(s) & System Info

  • Operating System: macOS 15.1.1 (24B91)
  • Python Version: Python 3.10.8
  • Package Version: Python-Markdown 3.7, PyMdown Extensions 10.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions