markdown: link/image/autolink conformance improvements - #18
Merged
Merged
Conversation
Improve CommonMark conformance for inline links, link reference definitions, images, and autolinks (Refs #10). Focused, low-risk fixes: - Autolinks: rewrite angle-autolink parsing to the CommonMark URI/email grammar. Try the URI (scheme) production before email so `<MAILTO:foo@bar.baz>` stays a scheme autolink; use the spec email grammar (no backslash in the local part); stop treating backslashes as escapes inside autolinks. Percent-encode `[`/`]` in href output. - Links: when a `[label](...)` inline destination fails to parse, fall through to shortcut-reference resolution instead of bailing, so `[foo](not a link)` links `[foo]` and keeps the parens as text. - Links/Images/Reference definitions: reject empty, whitespace-only, and bracket-nesting reference labels for both definitions and lookups, so `[]`, `[[[foo]]]`, and `[ref[bar]]` no longer form links. Newly passing spec examples (no regressions): Links 72->77 (547, 548, 551, 552, 568) Images 17->18 (590) Autolinks 14->16 (597, 603) Added unit tests for each behavior and regenerated the conformance baseline (510->518 passing, additive only). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cv1iyJb9PHMFG3YGp6ffkT
Collaborator
Author
|
Code review (high effort) — no correctness bugs found. ✅ Verified:
Low-severity note (non-blocking): dropping Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Focused, low-risk CommonMark conformance improvements for inline links, link reference definitions, images, and autolinks. Refs #10 (partial batch — does not close the issue).
Per-section conformance (before → after)
Total pinned passing examples: 510 → 518, additive only (no section decreased; the
passingarray only gains numbers).Newly passing spec examples
What changed
Autolinks (
src/inline-autolinks.ts) — rewrote angle-autolink parsing to the CommonMark URI/email grammar:<MAILTO:foo@bar.baz>is a scheme autolink with the href kept verbatim rather than being mangled intomailto:MAILTO:...(597).<foo\+@bar.example.com>is not an email autolink (606 — see gaps below).<https://example.com/\[\>is a valid autolink (603).Destination encoding (
src/link-references.ts) — percent-encode[and]in href output (%5B/%5D), matching the reference renderer (603).Inline links (
src/inline-links.ts) — when a[label](...)inline destination fails to parse, fall through to shortcut-reference resolution instead of bailing out, so[foo](not a link)links[foo]and keeps(not a link)as literal text (568).Reference label validity (
src/link-references.ts) — reject empty, whitespace-only, and bracket-nesting reference labels for both definitions and lookups, so[],[[[foo]]], and[ref[bar]]no longer form links or definitions (547, 548, 551, 552, 590). Escaped brackets ([Foo*bar\]]) remain valid.Tests
inline-autolinks.test.ts,inline-links.test.ts, andlink-references.test.ts(not relying solely on the conformance baseline).tests/fixtures/commonmark/conformance-baseline.json(additive only).npm run typecheckandnpm test(385 tests) fully green.Remaining gaps (not addressed here)
<foo\+@...>→<foo\+@...) becauseencodeBackslashEscapestreats the malformed email as a verbatim region; 608/611 involve the app's bare-URL autolinking, which is a deliberate extension over CommonMark.ẞ→SS): these are block-tokenizer concerns and left for a separate change.🤖 Generated with Claude Code
https://claude.ai/code/session_01Cv1iyJb9PHMFG3YGp6ffkT
Generated by Claude Code