diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 374650bf..02b87c37 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -4,7 +4,9 @@ ### Fixed * Add regression test confirming that types whose name matches their enclosing namespace are correctly included in generated API docs. [#944](https://github.com/fsprojects/FSharp.Formatting/issues/944) -* Fix crash (`failwith "tbd - IndirectImage"`) when `Markdown.ToMd` is called on a document containing reference-style images (`![alt][ref]`). The indirect image is now serialised as `![alt](url)` when the reference is resolved, or `![alt][ref]` when it is not. +* Fix crash (`failwith "tbd - IndirectImage"`) when `Markdown.ToMd` is called on a document containing reference-style images (`![alt][ref]`). The indirect image is now serialised as `![alt](url)` when the reference is resolved, or `![alt][ref]` when it is not. [#1094](https://github.com/fsprojects/FSharp.Formatting/pull/1094) +* Fix `Markdown.ToMd` serialising `*emphasis*` (italic) spans as `**...**` (bold) instead of `*...*`. [#1102](https://github.com/fsprojects/FSharp.Formatting/pull/1102) +* Fix `Markdown.ToMd` serialising ordered list items with 0-based numbering and no period (e.g. `0 first`) instead of 1-based with a period (e.g. `1. first`). [#1102](https://github.com/fsprojects/FSharp.Formatting/pull/1102) ## 22.0.0-alpha.2 - 2026-03-13 diff --git a/src/FSharp.Formatting.Markdown/MarkdownUtils.fs b/src/FSharp.Formatting.Markdown/MarkdownUtils.fs index c90f1c96..59bf09a3 100644 --- a/src/FSharp.Formatting.Markdown/MarkdownUtils.fs +++ b/src/FSharp.Formatting.Markdown/MarkdownUtils.fs @@ -115,7 +115,7 @@ module internal MarkdownUtils = | DirectImage(body, link, _, _) -> sprintf "![%s](%s)" body link | Strong(body, _) -> "**" + formatSpans ctx body + "**" | InlineCode(body, _) -> "`" + body + "`" - | Emphasis(body, _) -> "**" + formatSpans ctx body + "**" + | Emphasis(body, _) -> "*" + formatSpans ctx body + "*" /// Format a list of MarkdownSpan and formatSpans ctx spans = @@ -177,7 +177,7 @@ module internal MarkdownUtils = for (j, line) in List.indexed lines do if i = 0 && j = 0 then - yield $"%i{n} " + line + yield $"%i{n + 1}. " + line else yield " " + line diff --git a/tests/FSharp.Markdown.Tests/Markdown.fs b/tests/FSharp.Markdown.Tests/Markdown.fs index 57e928bc..984047f7 100644 --- a/tests/FSharp.Markdown.Tests/Markdown.fs +++ b/tests/FSharp.Markdown.Tests/Markdown.fs @@ -1257,6 +1257,33 @@ let ``ToMd preserves an unordered list`` () = result |> should contain "banana" result |> should contain "cherry" +[] +let ``ToMd preserves emphasis (italic) text`` () = + // Emphasis must serialise as *...* not **...** (bold) + "*italic*" |> toMd |> should contain "*italic*" + +[] +let ``ToMd preserves emphasis distinct from strong`` () = + let result = "**bold** and *italic*" |> toMd + result |> should contain "**bold**" + // Emphasis must not be rendered with double asterisks + result |> should not' (contain "**italic**") + result |> should contain "*italic*" + +[] +let ``ToMd preserves an ordered list with correct numbering`` () = + let result = "1. first\n2. second\n3. third" |> toMd + result |> should contain "1. first" + result |> should contain "2. second" + result |> should contain "3. third" + +[] +let ``ToMd ordered list does not use zero-based numbering`` () = + // Before fix: ordered list items were prefixed "0 ", "1 ", "2 " (0-indexed, no period) + let result = "1. only item" |> toMd + result |> should not' (contain "0 only item") + result |> should contain "1. only item" + [] let ``ToMd preserves a fenced code block`` () = let md = "```fsharp\nlet x = 1\n```"