Skip to content

🐛 FIX: Reserve inline footnote IDs before parsing content - #162

Open
civilwarinfrance wants to merge 1 commit into
executablebooks:masterfrom
civilwarinfrance:fix/inline-footnote-id-collisions
Open

civilwarinfrance wants to merge 1 commit into
executablebooks:masterfrom
civilwarinfrance:fix/inline-footnote-id-collisions

Conversation

@civilwarinfrance

Copy link
Copy Markdown

Inline notes allocate their ID before parsing their content but only insert the note afterward. If that content references another note, both notes receive the same ID and the outer note overwrites the inner one. A later reference can then raise KeyError('count').

Reproducer:

from markdown_it import MarkdownIt
from mdit_py_plugins.footnote import footnote_plugin

md = MarkdownIt().use(footnote_plugin)
md.render("^[outer [^named]] again[^named]\n\n[^named]: named body")

Reserve the outer note's entry before recursive inline parsing, retaining the same token list while it is populated. Each note then keeps its own ID and content. Fourteen regression cases cover named references, repeated references, nested inline notes, pre-existing notes and both move_to_end modes; rendered anchors must be unique and all internal targets must exist. Unchanged master fails 10 cases, with 4 controls passing. The docs and changelog describe the corrected behavior.

Validation through tox on macOS ARM64:

  • CPython 3.11.15 / markdown-it-py 4.2.0: 525 tests passed, 93% package coverage.
  • Strict mypy: all 40 source files pass.
  • Full pinned pre-commit hooks pass, including Ruff lint/format and Mypy.
  • Strict documentation build passes (tox -e docs-update).
  • git diff --check passes. Other platforms and hosted CI remain unverified.

AI disclosure: OpenAI Codex assisted with code inspection, reproduction, implementation, tests and this description. This is a reproduced code-inspection finding; no production incident, personal human review or upstream acceptance is claimed.

AI-assisted investigation, implementation and testing with OpenAI Codex.
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.

1 participant