Skip to content

Commit 8d7f4ef

Browse files
github-actions[bot]Copilotdsyme
authored
[Repo Assist] fix: handle EmbedParagraphs in Markdown.ToMd serialiser (#1145)
* fix: handle EmbedParagraphs in Markdown.ToMd serialiser Previously EmbedParagraphs fell through to the catch-all '| _' branch in MarkdownUtils.formatParagraph, emitting a debug printfn to stdout and yielding an empty string. All other formatters (HTML, LaTeX) delegate to cmd.Render() and recurse; this commit brings the Markdown-to-Markdown back-end into line with them. The now-dead catch-all branch is removed so the exhaustiveness checker will catch any new MarkdownParagraph cases that are added without a corresponding formatParagraph clause. Fixes: the debug 'can't yet format' output that appeared on stdout whenever a document containing EmbedParagraphs was serialised via Markdown.ToMd. 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> Co-authored-by: Don Syme <dsyme@users.noreply.github.com>
1 parent 3a8d8c3 commit 8d7f4ef

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
### Fixed
6+
* Fix `Markdown.ToMd` silently dropping `EmbedParagraphs` nodes: the serialiser now delegates to the node's `Render()` method and formats the resulting paragraphs, consistent with the HTML and LaTeX back-ends.
67
* Fix `Markdown.ToMd` dropping link titles in `DirectLink` and `DirectImage` spans. Links with a title attribute (e.g. `[text](url "title")`) now round-trip correctly; without this fix the title was silently discarded on serialisation.
78
* Fix `Markdown.ToMd` serialising inline code spans that contain backtick characters. Previously, `InlineCode` was always wrapped in single backticks, producing syntactically incorrect Markdown when the code body contained backticks. Now the serialiser selects the shortest backtick fence that does not collide with the body content (e.g. a double-backtick fence for bodies containing single backticks, triple for double, etc.), matching the CommonMark spec.
89

src/FSharp.Formatting.Markdown/MarkdownUtils.fs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,7 @@ module internal MarkdownUtils =
280280
yield "> " + line
281281

282282
yield ""
283-
| _ ->
284-
printfn "// can't yet format %0A to markdown" paragraph
285-
yield "" ]
283+
| EmbedParagraphs(cmd, _) -> yield! cmd.Render() |> Seq.collect (formatParagraph ctx) ]
286284

287285
/// Strips <c>#if SYMBOL</c> / <c>#endif // SYMBOL</c> conditional compilation lines from an .fsx code block
288286
/// so that format-specific sections are removed from non-target output formats.

tests/FSharp.Markdown.Tests/Markdown.fs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,3 +1417,17 @@ let ``ToMd round-trip: indirect image with unresolved reference`` () =
14171417
let result = Markdown.ToMd(doc)
14181418
// When key is not resolved, should preserve the indirect form
14191419
result |> should contain "![alt text][unknown-ref]"
1420+
1421+
[<Test>]
1422+
let ``ToMd serialises EmbedParagraphs by delegating to Render()`` () =
1423+
// EmbedParagraphs was previously falling through to the catch-all '| _' branch,
1424+
// emitting a debug printfn and yielding an empty string. It should instead
1425+
// delegate to the Render() method and format the resulting paragraphs.
1426+
let inner =
1427+
{ new MarkdownEmbedParagraphs with
1428+
member _.Render() =
1429+
[ Paragraph([ Literal("embedded text", MarkdownRange.zero) ], MarkdownRange.zero) ] }
1430+
1431+
let doc = MarkdownDocument([ EmbedParagraphs(inner, MarkdownRange.zero) ], dict [])
1432+
let result = Markdown.ToMd(doc)
1433+
result |> should contain "embedded text"

0 commit comments

Comments
 (0)