Skip to content

Commit 0b027d4

Browse files
[Repo Assist] Fix Markdown.ToMd: Emphasis serialised as bold; ordered list 0-indexed (#1102)
* Fix Markdown.ToMd: Emphasis serialised as bold, ordered list 0-indexed Two bugs in MarkdownUtils.fs formatSpan/formatParagraph: 1. Emphasis (italic) was serialised as **...** (bold) instead of *...*, causing round-trip loss: *italic* → **italic** 2. Ordered list items used 0-based indexing with no period: "0 first", "1 second" instead of "1. first", "2. second" Fix both and add four regression tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks * docs: add issue/PR links to all Unreleased release note entries Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 83c90a1 commit 0b027d4

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

RELEASE_NOTES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
### Fixed
66
* 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)
7-
* 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.
7+
* 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)
8+
* Fix `Markdown.ToMd` serialising `*emphasis*` (italic) spans as `**...**` (bold) instead of `*...*`. [#1102](https://github.com/fsprojects/FSharp.Formatting/pull/1102)
9+
* 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)
810

911
## 22.0.0-alpha.2 - 2026-03-13
1012

src/FSharp.Formatting.Markdown/MarkdownUtils.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ module internal MarkdownUtils =
115115
| DirectImage(body, link, _, _) -> sprintf "![%s](%s)" body link
116116
| Strong(body, _) -> "**" + formatSpans ctx body + "**"
117117
| InlineCode(body, _) -> "`" + body + "`"
118-
| Emphasis(body, _) -> "**" + formatSpans ctx body + "**"
118+
| Emphasis(body, _) -> "*" + formatSpans ctx body + "*"
119119

120120
/// Format a list of MarkdownSpan
121121
and formatSpans ctx spans =
@@ -177,7 +177,7 @@ module internal MarkdownUtils =
177177

178178
for (j, line) in List.indexed lines do
179179
if i = 0 && j = 0 then
180-
yield $"%i{n} " + line
180+
yield $"%i{n + 1}. " + line
181181
else
182182
yield " " + line
183183

tests/FSharp.Markdown.Tests/Markdown.fs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,33 @@ let ``ToMd preserves an unordered list`` () =
12571257
result |> should contain "banana"
12581258
result |> should contain "cherry"
12591259

1260+
[<Test>]
1261+
let ``ToMd preserves emphasis (italic) text`` () =
1262+
// Emphasis must serialise as *...* not **...** (bold)
1263+
"*italic*" |> toMd |> should contain "*italic*"
1264+
1265+
[<Test>]
1266+
let ``ToMd preserves emphasis distinct from strong`` () =
1267+
let result = "**bold** and *italic*" |> toMd
1268+
result |> should contain "**bold**"
1269+
// Emphasis must not be rendered with double asterisks
1270+
result |> should not' (contain "**italic**")
1271+
result |> should contain "*italic*"
1272+
1273+
[<Test>]
1274+
let ``ToMd preserves an ordered list with correct numbering`` () =
1275+
let result = "1. first\n2. second\n3. third" |> toMd
1276+
result |> should contain "1. first"
1277+
result |> should contain "2. second"
1278+
result |> should contain "3. third"
1279+
1280+
[<Test>]
1281+
let ``ToMd ordered list does not use zero-based numbering`` () =
1282+
// Before fix: ordered list items were prefixed "0 ", "1 ", "2 " (0-indexed, no period)
1283+
let result = "1. only item" |> toMd
1284+
result |> should not' (contain "0 only item")
1285+
result |> should contain "1. only item"
1286+
12601287
[<Test>]
12611288
let ``ToMd preserves a fenced code block`` () =
12621289
let md = "```fsharp\nlet x = 1\n```"

0 commit comments

Comments
 (0)