Skip to content

Fix indented footnote definitions being silently dropped - #1710

Closed
tony1233200 wants to merge 1 commit into
Python-Markdown:masterfrom
tony1233200:fix-indented-nested-footnote-1681
Closed

tony1233200 wants to merge 1 commit into
Python-Markdown:masterfrom
tony1233200:fix-indented-nested-footnote-1681

Conversation

@tony1233200

Copy link
Copy Markdown

Description

Fixes #1681. A footnote definition which is indented as content of another footnote definition (for example, [^2]: Second indented by four spaces under [^1]: First) was silently dropped: FootnoteBlockProcessor matched its definition pattern against the still-indented text, where the pattern cannot match, so the nested definition was never registered and any reference to it pointed at a #fn: anchor that does not exist in the output.

The block processor now also searches for a definition in the detabbed text, both when collecting the indented blocks of a footnote (detectTabbed) and when handling the rest of a footnote block (run). When an indented definition is found, the block is split at the definition so it is registered like an un-indented one. Only the definition line is detabbed; lines which follow it keep their original indentation, so indented content of the nested footnote (such as a code block) is preserved.

Three regression tests cover an indented definition in a following block, in the same block as its parent, and referenced by its parent. All three fail without the change. The full test suite (1221 tests via python -m unittest discover tests) passes with it.

AI Assistance Disclosure

  • No AI tools were used in preparing this PR.

  • AI tools were used and I have disclosed which ones, and have fully reviewed and verified their output.

    AI tools were use to assist with the following:

    • Code
    • Code Comments
    • Documentation
    • Changelog Entry
    • Commit Message
    • The Description Above
    • Other: ______________

    The tool used was Claude (Anthropic). It generated the code change in markdown/extensions/footnotes.py, the three regression tests, the changelog entry, the commit message, and this description. All output was reviewed, and the change was verified locally by reproducing the issue from Footnotes: indented nested footnote definition is silently dropped and produces a dead #fn: anchor #1681 and running the full test suite before submission.

Checklist

A footnote definition which is indented as content of another footnote
definition was never registered: the definition pattern was matched
against the still-indented text, where it cannot match. The definition
was therefore dropped and any reference to it pointed at a missing
anchor.

Search for a definition in the detabbed text when handling the rest of
a footnote block and when collecting indented blocks of a footnote, and
split the block at the definition when one is found. Only the
definition line is detabbed, so following lines keep their original
indentation.

Fixes Python-Markdown#1681
@waylan

waylan commented Nov 16, 2026

Copy link
Copy Markdown
Member

This is not the behavior I described as acceptable in #1710. If we are making any changes, those changes would be to better match PHP Markdown Extra's behavior. At a minimum, we should not recognize a footnote nested in a footnote. It should remain as text in the parent footnote.

@waylan waylan closed this Nov 16, 2026
@waylan waylan added the rejected The pull request is rejected for the stated reasons. label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rejected The pull request is rejected for the stated reasons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Footnotes: indented nested footnote definition is silently dropped and produces a dead #fn: anchor

2 participants