@@ -1202,6 +1202,124 @@ let ``Paragraph between sublists should not be absorbed into first sublist item
12021202 // Second sublist starts after paragraph.
12031203 secondSublistStart |> should be ( greaterThan paragraphPos)
12041204
1205+ // -----------------------------------------------------------------------
1206+ // ToMd serialisation tests
1207+ // These verify the round-trip Markdown-to-Markdown serialiser. Prior to
1208+ // this test file there was zero coverage of Markdown.ToMd.
1209+ // -----------------------------------------------------------------------
1210+
1211+ /// Round-trip helper: parse markdown, serialise back with ToMd (Unix newlines
1212+ /// so comparisons are platform-independent), then strip trailing whitespace.
1213+ let toMd ( input : string ) =
1214+ Markdown.Parse( input)
1215+ |> ( fun doc -> Markdown.ToMd( doc, newline = " \n " ))
1216+ |> ( fun s -> s.TrimEnd())
1217+
1218+ [<Test>]
1219+ let ``ToMd preserves a plain paragraph`` () =
1220+ " Hello, world." |> toMd |> should contain " Hello, world."
1221+
1222+ [<Test>]
1223+ let ``ToMd preserves a level - 1 heading`` () =
1224+ " # Heading One" |> toMd |> shouldEqual " # Heading One"
1225+
1226+ [<Test>]
1227+ let ``ToMd preserves a level - 2 heading`` () =
1228+ " ## Heading Two" |> toMd |> shouldEqual " ## Heading Two"
1229+
1230+ [<Test>]
1231+ let ``ToMd preserves a level - 3 heading`` () =
1232+ " ### Heading Three" |> toMd |> shouldEqual " ### Heading Three"
1233+
1234+ [<Test>]
1235+ let ``ToMd preserves strong ( bold ) text`` () =
1236+ " **bold**" |> toMd |> should contain " **bold**"
1237+
1238+ [<Test>]
1239+ let ``ToMd preserves inline code`` () =
1240+ " Use `printf` here." |> toMd |> should contain " `printf`"
1241+
1242+ [<Test>]
1243+ let ``ToMd preserves a direct link`` () =
1244+ " [FSharp](https://fsharp.org)"
1245+ |> toMd
1246+ |> should contain " [FSharp](https://fsharp.org)"
1247+
1248+ [<Test>]
1249+ let ``ToMd preserves a direct image`` () =
1250+ " " |> toMd |> should contain " "
1251+
1252+ [<Test>]
1253+ let ``ToMd preserves an unordered list`` () =
1254+ let md = " * apple\n * banana\n * cherry"
1255+ let result = toMd md
1256+ result |> should contain " apple"
1257+ result |> should contain " banana"
1258+ result |> should contain " cherry"
1259+
1260+ [<Test>]
1261+ let ``ToMd preserves a fenced code block`` () =
1262+ let md = " ```fsharp\n let x = 1\n ```"
1263+ let result = toMd md
1264+ result |> should contain " let x = 1"
1265+ result |> should contain " ```"
1266+
1267+ [<Test>]
1268+ let ``ToMd preserves a blockquote`` () =
1269+ let md = " > This is a quote."
1270+ let result = toMd md
1271+ result |> should contain " > "
1272+ result |> should contain " This is a quote."
1273+
1274+ [<Test>]
1275+ let ``ToMd preserves a horizontal rule`` () =
1276+ let md = " Before\n\n ---\n\n After"
1277+ let result = toMd md
1278+ result |> should contain " Before"
1279+ result |> should contain " ---"
1280+ result |> should contain " After"
1281+
1282+ [<Test>]
1283+ let ``ToMd preserves LaTeX inline math`` () =
1284+ let md = " Einstein's $E = mc^2$ equation."
1285+ let result = toMd md
1286+ result |> should contain " $E = mc^2$"
1287+
1288+ [<Test>]
1289+ let ``ToMd preserves inline HTML block`` () =
1290+ let md = " <div class=\" note\" >Note content</div>"
1291+ let result = toMd md
1292+ result |> should contain " <div"
1293+ result |> should contain " Note content"
1294+
1295+ [<Test>]
1296+ let ``ToMd handles a document with heading and paragraph`` () =
1297+ let md = " # Title\n\n Body text here."
1298+ let result = toMd md
1299+ result |> should contain " # Title"
1300+ result |> should contain " Body text here."
1301+
1302+ [<Test>]
1303+ let ``ToMd handles a table`` () =
1304+ let md = " Col1 | Col2\n :--- | :---\n A | B"
1305+ let result = toMd md
1306+ result |> should contain " Col1"
1307+ result |> should contain " Col2"
1308+ result |> should contain " A"
1309+ result |> should contain " B"
1310+
1311+ [<Test>]
1312+ let ``ToMd handles empty document`` () = " " |> toMd |> shouldEqual " "
1313+
1314+ [<Test>]
1315+ let ``ToMd preserves an indirect link when key is not resolved`` () =
1316+ // Indirect link whose reference definition is present — should round-trip
1317+ let md = " [link text][ref]\n\n [ref]: https://example.com"
1318+ let result = toMd md
1319+ // ToMd resolves the indirect link to a direct link form
1320+ result |> should contain " [link text]"
1321+ result |> should contain " https://example.com"
1322+
12051323// --------------------------------------------------------------------------------------
12061324// ToMd round-trip: indirect images (issue - failwith "tbd - IndirectImage")
12071325// --------------------------------------------------------------------------------------
0 commit comments