Skip to content

fix(markdown): preserve first-reference order for Unicode footnotes - #38

Merged
palmoni5 merged 1 commit into
mainfrom
palmoni5/markdown-unicode-footnote-order-20261111
Nov 11, 2026
Merged

palmoni5 merged 1 commit into
mainfrom
palmoni5/markdown-unicode-footnote-order-20261111

Conversation

@palmoni5

@palmoni5 palmoni5 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Bug

Document._filterFootnotes() builds its ordinal map from the raw (lower-cased) reference labels, keyed as fn-<label>, but looks each definition up by its lower-cased, URI-encoded HTML id. For any label containing a character that Uri.encodeComponent escapes (Hebrew and other non-ASCII text, \[, %, &, emoji, ...) the keys never match, every such definition gets ordinal 0, and the footnote list falls back to definition order, so its numbering no longer matches the reference numbers in the text.

Fix

Look definitions up by Element.footnoteLabel, lower-cased the same way FootnoteRefSyntax normalizes reference keys. Every emitted definition now has a unique ordinal, so the order no longer depends on sort stability.

Tests

  • Hebrew footnotes defined in reverse order of first reference.
  • An escaped-punctuation label (\[) referenced second but defined first.
    Both fail before the fix and pass after it. Existing ASCII case-folding tests are unchanged.

Verification

Output is byte-identical to main for all CommonMark/GFM spec inputs and for every README/CHANGELOG in a local pub cache. In 20,000 fuzzed footnote documents every difference from main is a corrected order (definition N in the list is the one whose reference shows N).

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

PR Health

Publish ✔️
Package Version Status Publish tag (post-merge)
package:markdown ⭐ 7.4.1-wip WIP (no publish necessary)
  • 16 already published.
  • 26 WIP (no publish necessary).

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

This check can be disabled by tagging the PR with skip-publish-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check (for example, for non-user-visible changes when the package version is already at -wip).

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
markdown Non-Breaking 7.3.1 7.4.1-wip 7.4.1-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Unused Dependencies ✔️
Package Status
markdown ✔️ All dependencies utilized correctly.

For details on how to fix these, see dependency_validator.

This check can be disabled by tagging the PR with skip-unused-dependencies-check.

License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/html/test/differential_test.dart
pkgs/html/test/dom_parsing_test.dart
pkgs/html/test/mxss_test.dart
pkgs/html/test/noah_ark_clause_limit_test.dart

This check can be disabled by tagging the PR with skip-license-check.

Coverage ⚠️
File Coverage
pkgs/markdown/lib/src/document.dart 💔 96 % ⬇️ 0 %

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

@palmoni5
palmoni5 force-pushed the palmoni5/markdown-unicode-footnote-order-20261111 branch from 272c653 to dfb0714 Compare November 11, 2026 17:00
@palmoni5
palmoni5 merged commit 80fecb9 into main Nov 11, 2026
17 checks passed
@palmoni5
palmoni5 deleted the palmoni5/markdown-unicode-footnote-order-20261111 branch November 11, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant