diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 8a318b6a..dbe5f2ec 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -17,6 +17,7 @@ * 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. * Remove stray `printfn` debug output emitted to stdout when `Markdown.ToMd` encountered an unrecognised paragraph type. * 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. +* 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. ### Added * Add tests for `Markdown.ToFsx` (direct serialisation to F# script format), which previously had no unit test coverage. diff --git a/src/FSharp.Formatting.Markdown/MarkdownUtils.fs b/src/FSharp.Formatting.Markdown/MarkdownUtils.fs index 6b784184..257bda27 100644 --- a/src/FSharp.Formatting.Markdown/MarkdownUtils.fs +++ b/src/FSharp.Formatting.Markdown/MarkdownUtils.fs @@ -113,8 +113,8 @@ module internal MarkdownUtils = "[" + formatSpans ctx body + "](" + link + t + ")" - | IndirectLink(body, _, LookupKey ctx.Links (link, _), _) - | IndirectLink(body, link, _, _) -> "[" + formatSpans ctx body + "](" + link + ")" + | IndirectLink(body, _, LookupKey ctx.Links (link, _), _) -> "[" + formatSpans ctx body + "](" + link + ")" + | IndirectLink(body, _, key, _) -> "[" + formatSpans ctx body + "][" + key + "]" | IndirectImage(body, _, LookupKey ctx.Links (link, _), _) -> sprintf "![%s](%s)" body link | IndirectImage(body, _, key, _) -> sprintf "![%s][%s]" body key diff --git a/tests/FSharp.Markdown.Tests/Markdown.fs b/tests/FSharp.Markdown.Tests/Markdown.fs index 9c91c63d..ffd4ccfb 100644 --- a/tests/FSharp.Markdown.Tests/Markdown.fs +++ b/tests/FSharp.Markdown.Tests/Markdown.fs @@ -1418,6 +1418,15 @@ let ``ToMd preserves an indirect link when key is not resolved`` () = result |> should contain "[link text]" result |> should contain "https://example.com" +[] +let ``ToMd preserves indirect link form when key is unresolved`` () = + // No reference definition → key cannot be resolved; should preserve [body][key] form + let input = "[link text][unknown-ref]" + let doc = Markdown.Parse(input) + let result = Markdown.ToMd(doc) + // Should preserve the indirect reference form, not produce a broken direct link + result |> should contain "[link text][unknown-ref]" + // -------------------------------------------------------------------------------------- // ToMd round-trip: indirect images (issue - failwith "tbd - IndirectImage") // --------------------------------------------------------------------------------------