Skip to content

Do not recognize footnote definitions within a footnote - #1711

Merged
waylan merged 4 commits into
Python-Markdown:masterfrom
tony1233200:nested-footnote-definition-as-text-1681
Nov 26, 2026
Merged

waylan merged 4 commits into
Python-Markdown:masterfrom
tony1233200:nested-footnote-definition-as-text-1681

Conversation

@tony1233200

Copy link
Copy Markdown
Contributor

Description

This replaces #1710 with the behavior @waylan described as acceptable on #1681: footnote definitions are not recognized within a footnote definition (matching PHP Markdown Extra), so a nested definition remains as text in the parent footnote.

Previously, an indented definition nested in another footnote's content was extracted when the parent footnote's content was rendered — too late to appear in the footnotes div. The definition text was silently dropped, and a reference to it produced a link to a #fn: anchor that never exists.

The change has two parts:

  • FootnoteBlockProcessor is disabled while footnote content is being rendered (FootnoteExtension.parsing_footnotes, set around the parseChunk calls in makeFootnotesDiv). A nested definition is left as content of the footnote being rendered, and references to it stay unresolved text — no dead anchor.
  • ReferenceProcessor no longer matches a definition whose identifier starts with ^. That is footnote definition syntax (at the top level such lines are always claimed by the footnote processor first, so this only changes the footnote-content path, where the line was previously swallowed as a link reference and vanished).

With the issue's example, footnote 1 now renders as:

<li id="fn:1">
<p>First</p>
<p>[^2]: Second&#160;<a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>

Two regression tests cover the nested definition on its own and referenced from the parent footnote; both fail without the fix. The full test suite passes (1223 tests). A changelog entry is included.

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 AI tool used was Claude. I reproduced the issue, reviewed the maintainer's guidance on acceptable behavior, verified the rendered output against it, and ran the full test suite myself.

Checklist

@waylan waylan added the needs-review Needs to be reviewed and/or approved. label Nov 16, 2026
@tony1233200

Copy link
Copy Markdown
Contributor Author

Closing this one to keep the queue clear — it has had no maintainer reply in 7 days. The branch stays in my fork, and I'm happy to reopen it if there's interest.

@waylan waylan reopened this Nov 24, 2026
@waylan

waylan commented Nov 24, 2026

Copy link
Copy Markdown
Member

I added the needs-review label, which means I will review it when I get to it. That could be later today. It could be six months from now. I do this in my spare time so my time is limited.

@tony1233200
tony1233200 force-pushed the nested-footnote-definition-as-text-1681 branch from 4d20ff3 to 7791d37 Compare November 25, 2026 12:33
Comment thread markdown/blockprocessors.py Resolved
@waylan waylan added requires-changes Awaiting updates after a review. and removed needs-review Needs to be reviewed and/or approved. labels Nov 25, 2026
@waylan

waylan commented Nov 26, 2026

Copy link
Copy Markdown
Member

This looks good. However, it needs to be merged with master and the changelog entry will need to be moved to a new unreleased version. Then it should be ready to go.

yc25778-droid and others added 4 commits November 26, 2026 22:36
An indented footnote definition nested in another footnote's content
was extracted when the parent footnote was rendered, too late to be
included in the footnotes div: the definition text was silently
dropped and references to it produced links to a missing anchor.

Matching PHP Markdown Extra, definitions are no longer recognized
within a footnote definition: the FootnoteBlockProcessor is disabled
while footnote content is being rendered, so a nested definition
remains as text in the parent footnote and references to it stay
unresolved. The ReferenceProcessor no longer treats a definition
with an identifier starting with '^' as a link reference, as that
is footnote definition syntax; this keeps the nested definition
from being swallowed as a link reference instead.

Fixes Python-Markdown#1681
The core ReferenceProcessor must not know about footnotes: the '^'
exclusion now lives in a FootnoteReferenceProcessor in the footnotes
extension, registered under the same name and priority only while the
extension is loaded. Without the extension, '[^a]: ...' is still a
link reference.

Fixes Python-Markdown#1681
The 3.11.4 release landed while this PR was in review; the Python-Markdown#1681
entry moves back under a new Unreleased section.
@tony1233200
tony1233200 force-pushed the nested-footnote-definition-as-text-1681 branch from b765b4a to a435dbb Compare November 26, 2026 22:37
@tony1233200

Copy link
Copy Markdown
Contributor Author

Done — rebased onto master (now at 3.11.4) and moved the #1681 changelog entry to a new Unreleased section. Pushed as a435dbb (rebased branch: 4f253ff, 2061e42, 609bb66, a435dbb). Full test suite passes: 911 passed, 111 skipped, plus 345 passed in test_md_in_html.py.

@waylan
waylan merged commit b818f41 into Python-Markdown:master Nov 26, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires-changes Awaiting updates after a review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants