miyuchina / mistletoe

A fast, extensible and spec-compliant Markdown parser in pure Python.
MIT License
791 stars 110 forks source link

Footnote not processed if there is a whitespace in text #216

Closed nsarang closed 1 month ago

nsarang commented 1 month ago

Hi folks, I've encountered an issue where footnote tokens aren't properly tagged if there is any white space in the text.

Example

from mistletoe import block_token

lines = '''
[^1]: Works
[^2]: Not working
'''
token = block_token.Document(lines)
print(token.footnotes)

outputs:

{'^1': ('Works', '')}

While removing the space produces:

{'^1': ('Works', ''), '^2': ('Notworking', '')}
pbodnar commented 1 month ago

@nsarang, thanks for the report. The actual problem is that mistletoe doesn't support footnotes in the form as for example GitHub here does -> see #47 for the feature request.

Instead, mistletoe only supports so called link reference definitions as described in the CommonMark Spec: https://spec.commonmark.org/0.30/#link-reference-definitions. That's why [^2]: Not working is treated as a plain text - because it matches the case from spec's Example 209. Historically, mistletoe uses term "footnotes" for these, which I admit might be confusing...

nsarang commented 1 month ago

Thanks for the clarification @pbodnar