Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Formatting.Markdown/MarkdownUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/FSharp.Markdown.Tests/Markdown.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"

[<Test>]
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")
// --------------------------------------------------------------------------------------
Expand Down