Skip to content

Fix silently dropped indented nested footnote definitions - #1682

Open
rahul05ranjan wants to merge 1 commit into
Python-Markdown:masterfrom
rahul05ranjan:fix/footnotes-indented-nested-definition
Open

rahul05ranjan wants to merge 1 commit into
Python-Markdown:masterfrom
rahul05ranjan:fix/footnotes-indented-nested-definition

Conversation

@rahul05ranjan

Copy link
Copy Markdown

Fixes #1681

Summary

An indented footnote definition nested inside another footnote's multi-line content was silently dropped: the definition text disappeared from the output entirely, and any reference to it linked to a #fn: anchor that was never emitted (dead internal link). The un-indented variant (definition in the same block as the parent) already worked and is tested, so only the multi-line/indented variant was broken.

Root cause

FootnoteBlockProcessor.detectTabbed() collected each 4-space-indented block as content of the parent footnote, but ran the definition regex (^[ ]{0,3}\[\^([^\]]*)\]:) on the still-indented block, so an indented [^2]: ... line never matched and was swallowed into the parent's content. When the parent content was later re-rendered internally, run() matched the now-unindented line as a new definition and removed it — after the footnote <div>/<ol> structure had already been generated, so the nested footnote was never rendered.

The fix

Run the definition search on the detab()-ed block inside detectTabbed() so an indented nested definition is split out and re-queued for the normal definition processing — exactly like the un-indented case. Double-indented (8-space) content is preserved as code inside the parent instead of being dropped.

Verification

  • Before/after minimal repro (see issue Footnotes: indented nested footnote definition is silently dropped and produces a dead #fn: anchor #1681): [^1]: First followed by an indented [^2]: Second now renders both <li id="fn:1"> and <li id="fn:2">; the referenced variant emits a matching #fn:2 anchor instead of a dead link.
  • 3 new regression tests in tests/test_syntax/extensions/test_footnotes.py:
    • indented nested definition renders as its own footnote
    • indented nested definition that is referenced emits a working anchor pair (fnref:2 ↔ fn:2)
    • indented nested definition preceded by continuation content keeps the content in the parent footnote
  • Full suite locally: 847 passed, 111 skipped (Python 3.13), including the existing test_footnote_reference_within_footnote_definition (un-indented nesting) — no regressions.

View the OpenClaw team session

An indented footnote definition nested inside another footnote's
multi-line content was collected as parent content (detectTabbed ran
the definition regex on the still-indented block), then removed again
when the parent content was re-rendered internally - after the
footnote list had already been built. The nested definition text
disappeared from the output and any reference to it linked to a
#fn: anchor that was never emitted.

Run the definition search on the detabbed block in detectTabbed so an
indented nested definition is split out and processed as its own
footnote in the same pass, exactly like an un-indented nested
definition. Double-indented content is preserved (as code) instead of
being dropped.

Fixes Python-Markdown#1681

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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

1 participant