Skip to content

Commit b4fdf16

Browse files
test: add OutputBlock, AnchorLink, and code-block language tests
Add four unit tests that cover previously-untested paths in Markdown.ToMd and Markdown.ToHtml: - ToMd preserves fenced code block language specifier (```fsharp) - ToMd serialises OutputBlock non-HTML as a fenced code block - ToMd serialises OutputBlock HTML as raw inline HTML (no fence) - ToHtml renders AnchorLink as a named anchor element All 350 FSharp.Markdown.Tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ccb080b commit b4fdf16

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/FSharp.Markdown.Tests/Markdown.fs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,3 +1894,45 @@ let ``ToLatex EmbedParagraphs delegates to Render()`` () =
18941894
let doc = MarkdownDocument([ EmbedParagraphs(inner, MarkdownRange.zero) ], dict [])
18951895
let result = Markdown.ToLatex(doc)
18961896
result |> should contain "latex text"
1897+
1898+
// --------------------------------------------------------------------------------------
1899+
// ToMd: untested paragraph types — OutputBlock, code-block language specifier
1900+
// --------------------------------------------------------------------------------------
1901+
1902+
[<Test>]
1903+
let ``ToMd preserves fenced code block language specifier`` () =
1904+
// Existing test only checks the code body; this test verifies the language tag is kept.
1905+
let md = "```fsharp\nlet x = 1\n```"
1906+
let result = toMd md
1907+
result |> should contain "```fsharp"
1908+
1909+
[<Test>]
1910+
let ``ToMd serialises OutputBlock non-HTML as fenced code block`` () =
1911+
// OutputBlock with a non-HTML kind should be wrapped in a fenced code block.
1912+
let doc = MarkdownDocument([ OutputBlock("hello output", "text/plain", None) ], dict [])
1913+
let result = Markdown.ToMd(doc, newline = "\n")
1914+
result |> should contain "```"
1915+
result |> should contain "hello output"
1916+
1917+
[<Test>]
1918+
let ``ToMd serialises OutputBlock HTML as raw HTML`` () =
1919+
// OutputBlock with kind "text/html" should emit the HTML directly, not wrapped in a fence.
1920+
let doc = MarkdownDocument([ OutputBlock("<p>output</p>", "text/html", None) ], dict [])
1921+
let result = Markdown.ToMd(doc, newline = "\n")
1922+
result |> should contain "<p>output</p>"
1923+
result |> should not' (contain "```")
1924+
1925+
// --------------------------------------------------------------------------------------
1926+
// ToHtml: AnchorLink renders as a named anchor element
1927+
// --------------------------------------------------------------------------------------
1928+
1929+
[<Test>]
1930+
let ``ToHtml renders AnchorLink as named anchor`` () =
1931+
// AnchorLink is used internally by ApiDocs to emit in-page anchors.
1932+
// It should produce <a name="id">&#160;</a> in HTML output.
1933+
let doc =
1934+
MarkdownDocument([ Paragraph([ AnchorLink("my-section", MarkdownRange.zero) ], MarkdownRange.zero) ], dict [])
1935+
1936+
let result = Markdown.ToHtml(doc)
1937+
result |> should contain "name=\"my-section\""
1938+
result |> should contain "<a "

0 commit comments

Comments
 (0)