[Repo Assist] fix: Markdown.ToMd preserves unresolved IndirectLink in reference notation#1153
Draft
github-actions[bot] wants to merge 2 commits intomainfrom
Draft
Conversation
…ation When a document contains a reference-style link whose key is not defined in the link dictionary (e.g. '[text][key]' with no '[key]: url' definition), the previous code emitted '[text]([key])' — treating the raw '[key]' string (including brackets) as the URL, producing broken Markdown. Root cause: the three-way OR pattern IndirectLink(resolved) | DirectLink | IndirectLink(fallthrough) bound 'link' to the 'original' field (position 2) of IndirectLink for the fallthrough arm. 'original' is the raw key text with surrounding brackets (e.g. '[unknown-key]'), not a URL. Fix: split the fallthrough into a dedicated pattern arm that uses the 'key' field (position 3 — the clean key string without brackets) and emits the correct '[text][key]' reference notation. Added 2 tests: - unresolved indirect link emits [text][key] - resolved indirect link (reference present) resolves to direct form All 283 Markdown tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Fixes a bug in
Markdown.ToMdwhere a reference-style link whose definition is absent from the document would serialise as invalid Markdown.Before (broken):
[link text]([unknown-key])— the raw[key]string used as a URLAfter (correct):
[link text][unknown-key]— proper reference-link notationRoot Cause
In
MarkdownUtils.formatSpan, theIndirectLinkcases were written as a three-way OR pattern:In the fallthrough arm (
IndirectLink(body, link, _, _)),linkbinds to position 2 ofIndirectLink— theoriginalfield — which contains the raw key text including brackets (e.g."[unknown-key]"). Using that as the URL produced[text]([unknown-key]), which is broken Markdown.Fix
Split the fallthrough into its own arm and use the correct
keyfield (position 3 — the clean key string):The corresponding
IndirectImagefallthrough was already correct (it usedkeyfrom position 3), so no change was needed there.Tests Added
ToMd preserves unresolved indirect link in reference notation— verifies the broken[text]([form no longer appearsToMd resolves indirect link when reference is present— verifies the resolved case still emits a direct link formTest Status
✅ Build: 0 warnings, 0 errors
✅
FSharp.Markdown.Tests: 283/283 passed (including 2 new tests)Trade-offs
None. This is a pure correctness fix. The resolved-link behaviour (when a
[key]: urldefinition is present) is unchanged.Note: this change touches the same region as #1150 (DirectLink title fix); when both are eventually merged, the merge will be trivial to resolve.