Case‑Sensitive or Case‑Insensitive Markdown Link References: Choosing Spec Compliance vs. Legacy Compliance
0 reputation · 31 May 2023, 17:33 UTC
0 reputation · 31 May 2023, 17:33 UTC
Determine whether Markdown parsers should enforce the CommonMark‑specified case‑insensitive matching for link reference definitions or provide a configurable case‑sensitive mode to accommodate legacy content that depends on exact case.
The goal is to balance spec compliance, which improves cross‑engine consistency and authoring ergonomics, against the risk of breaking existing documents that were written for case‑sensitive engines and the added complexity of supporting a legacy mode.
Should the default behavior follow the CommonMark spec (case‑insensitive) with an opt‑in flag for case‑sensitive matching, or should parsers default to case‑sensitive and offer a spec‑compliant switch? How should documentation and versioning guide authors when migrating between parsers that differ in reference‑case handling?
32275 reputation · 01 Jun 2023, 02:54 UTC
Default to CommonMark case-insensitive matching for link reference definitions. Provide a case-sensitive mode only as an explicit, documented opt-in flag for legacy content.
Confirmed: CommonMark normalizes reference labels by trimming leading and trailing whitespace and applying Unicode case folding before comparison. As a result, [Foo], [foo], and [FOO] resolve to the same definition, and when multiple definitions collide under folding, the first definition in the document wins.
Likely legacy risk: documents authored for case-sensitive engines may depend on labels that differ only by case. Under the spec default, those labels collapse into a single reference and later definitions are silently ignored. This is the only scenario that justifies a legacy mode, and because it is an extension beyond CommonMark, it should never be the default.
Before changing defaults, confirm behavior with a minimal test file:
[Foo]: /a
[foo]: /b
[FOO]: /c
See [Foo], [foo], and [FOO].
Under CommonMark defaults, all three links resolve to /a. Under a case-sensitive legacy mode, they resolve to /a, /b, and /c respectively.
Does your current corpus contain link reference definitions whose labels differ only by case? If yes, the legacy opt-in is mandatory for those documents and should be documented prominently. If no, the spec-compliant default is safe and the legacy flag can remain experimental.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.