From c4d636594ed6e408d84eb4511ff20bbd75bd93f4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2026 11:10:23 +0000 Subject: [PATCH 1/2] fix: Markdown.ToMd preserves YAML frontmatter When Markdown.ToMd serialises a parsed MarkdownDocument back to Markdown text, YamlFrontmatter paragraphs were silently dropped. Documents containing a YAML front-matter block (--- ... ---) would lose that block on round-trip. Fix: emit the --- delimiters and frontmatter lines in formatParagraph so round-trips are lossless. Add two new tests: one with populated frontmatter and one with an empty block. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- RELEASE_NOTES.md | 3 +++ src/FSharp.Formatting.Markdown/MarkdownUtils.fs | 9 ++++++++- tests/FSharp.Markdown.Tests/Markdown.fs | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 33214cbc..e75a4d5e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -2,6 +2,9 @@ ## [Unreleased] +### Fixed +* Fix `Markdown.ToMd` silently dropping YAML frontmatter when serialising a parsed `MarkdownDocument` back to Markdown text. Frontmatter is now preserved with its `---` delimiters. + ## [22.0.0] - 2026-04-03 ### Fixed diff --git a/src/FSharp.Formatting.Markdown/MarkdownUtils.fs b/src/FSharp.Formatting.Markdown/MarkdownUtils.fs index 59bf09a3..1ad7bc40 100644 --- a/src/FSharp.Formatting.Markdown/MarkdownUtils.fs +++ b/src/FSharp.Formatting.Markdown/MarkdownUtils.fs @@ -235,7 +235,14 @@ module internal MarkdownUtils = let lines = code.Replace("\r\n", "\n").Split('\n') |> Array.toList yield! lines //yield "" - | YamlFrontmatter _ -> () + | YamlFrontmatter(lines, _) -> + yield "---" + + for line in lines do + yield line + + yield "---" + yield "" | Span(body = body) -> yield formatSpans ctx body | QuotedBlock(paragraphs = paragraphs) -> for paragraph in paragraphs do diff --git a/tests/FSharp.Markdown.Tests/Markdown.fs b/tests/FSharp.Markdown.Tests/Markdown.fs index 984047f7..b9559702 100644 --- a/tests/FSharp.Markdown.Tests/Markdown.fs +++ b/tests/FSharp.Markdown.Tests/Markdown.fs @@ -1371,3 +1371,19 @@ let ``ToMd round-trip: indirect image with unresolved reference`` () = let result = Markdown.ToMd(doc) // When key is not resolved, should preserve the indirect form result |> should contain "![alt text][unknown-ref]" + +[] +let ``ToMd preserves YAML frontmatter`` () = + let input = "---\ntitle: My Page\ndate: 2024-01-01\n---\n\nHello world.\n" + let result = input |> toMd + result |> should contain "---" + result |> should contain "title: My Page" + result |> should contain "date: 2024-01-01" + result |> should contain "Hello world." + +[] +let ``ToMd preserves empty YAML frontmatter`` () = + let input = "---\n---\n\nHello.\n" + let result = input |> toMd + result |> should contain "---" + result |> should contain "Hello." From b2a8e4bce9af073bdc465e28efd36f16fb9e5ff3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 13 Apr 2026 11:10:26 +0000 Subject: [PATCH 2/2] ci: trigger checks