Skip to content

Commit 07eb033

Browse files
[Repo Assist] fix: Markdown.ToMd preserves [body][key] form for unresolved indirect links (#1185)
* fix: Markdown.ToMd preserves [body][key] form for unresolved indirect links Previously the unresolved-key fallback for IndirectLink used the second field (original) as a direct-link URL, producing '[body](key)' which treats the reference key as a URL. This was inconsistent with IndirectImage, which preserves '![body][key]' when the key is unresolved. Fix: split the two IndirectLink cases so the resolved path produces a direct link '[body](url)' and the unresolved path preserves the indirect form '[body][key]', matching IndirectImage behaviour. Added test: 'ToMd preserves indirect link form when key is unresolved' (347/347 Markdown tests pass). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 0209e5b commit 07eb033

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Fix `Markdown.ToMd` serialising `HorizontalRule` as 23 hyphens regardless of the character used in the source. It now emits exactly three characters matching the parsed character (`---`, `***`, or `___`), giving faithful round-trips.
1818
* Remove stray `printfn` debug output emitted to stdout when `Markdown.ToMd` encountered an unrecognised paragraph type.
1919
* Fix `Markdown.ToLatex` producing invalid LaTeX output for level-6 (and deeper) headings. Previously the LaTeX command was an empty string, resulting in bare `{content}` without a command prefix. Headings at level 6+ are now serialised as `\subparagraph{...}`, which is the deepest sectioning command available in LaTeX.
20+
* Fix `Markdown.ToMd` serialising unresolved indirect links as `[body](key)` (treating the reference key as a URL) instead of the correct `[body][key]` form. Unresolved indirect links are now preserved in their original indirect-reference form, consistent with how unresolved indirect images are handled.
2021

2122
### Added
2223
* Add tests for `Markdown.ToFsx` (direct serialisation to F# script format), which previously had no unit test coverage.

src/FSharp.Formatting.Markdown/MarkdownUtils.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ module internal MarkdownUtils =
113113

114114
"[" + formatSpans ctx body + "](" + link + t + ")"
115115

116-
| IndirectLink(body, _, LookupKey ctx.Links (link, _), _)
117-
| IndirectLink(body, link, _, _) -> "[" + formatSpans ctx body + "](" + link + ")"
116+
| IndirectLink(body, _, LookupKey ctx.Links (link, _), _) -> "[" + formatSpans ctx body + "](" + link + ")"
117+
| IndirectLink(body, _, key, _) -> "[" + formatSpans ctx body + "][" + key + "]"
118118

119119
| IndirectImage(body, _, LookupKey ctx.Links (link, _), _) -> sprintf "![%s](%s)" body link
120120
| IndirectImage(body, _, key, _) -> sprintf "![%s][%s]" body key

tests/FSharp.Markdown.Tests/Markdown.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,15 @@ let ``ToMd preserves an indirect link when key is not resolved`` () =
14181418
result |> should contain "[link text]"
14191419
result |> should contain "https://example.com"
14201420

1421+
[<Test>]
1422+
let ``ToMd preserves indirect link form when key is unresolved`` () =
1423+
// No reference definition → key cannot be resolved; should preserve [body][key] form
1424+
let input = "[link text][unknown-ref]"
1425+
let doc = Markdown.Parse(input)
1426+
let result = Markdown.ToMd(doc)
1427+
// Should preserve the indirect reference form, not produce a broken direct link
1428+
result |> should contain "[link text][unknown-ref]"
1429+
14211430
// --------------------------------------------------------------------------------------
14221431
// ToMd round-trip: indirect images (issue - failwith "tbd - IndirectImage")
14231432
// --------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)