File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
src/FSharp.Formatting.Literate
tests/FSharp.Literate.Tests Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -138,9 +138,11 @@ module internal ParsePynb =
138138 | " code" -> getCode cell
139139 | _ -> failwith $" unknown cell type {cell_type}"
140140
141- let ipynbToMarkdown ipynbFile =
142- let json = JsonDocument.Parse( File.ReadAllText ( ipynbFile ) )
141+ let pynbStringToMarkdown ( ipynb : string ) =
142+ let json = JsonDocument.Parse( ipynb )
143143
144144 json.RootElement.GetProperty( " cells" ) .EnumerateArray()
145145 |> Seq.map ( parseCell >> ( fun x -> x.ToMarkdown()))
146- |> String.concat " \n\n "
146+ |> String.concat " "
147+
148+ let pynbToMarkdown ipynbFile = ipynbFile |> File.ReadAllText |> pynbStringToMarkdown
Original file line number Diff line number Diff line change @@ -1433,6 +1433,34 @@ let goodbye = 2
14331433
14341434 pynb2 |> shouldEqual expected2
14351435
1436+ [<Test>]
1437+ let ``md - -> pynb - -> md comes back the same`` () =
1438+ let mdIn = """ Heading
1439+ =======
1440+
1441+ | Col1 | Col2 |
1442+ |:----:|------|
1443+ | Table with heading cell A1 | Table with heading cell B1 |
1444+ | Table with heading cell A2 | Table with heading cell B2 |
1445+
1446+ ```fsharp
1447+ let add a b = a + b
1448+ ```
1449+
1450+ ```csharp
1451+ ```
1452+
1453+ ```python
1454+ ```
1455+ """
1456+ let mdOut =
1457+ Literate.ParseMarkdownString( mdIn,
1458+ parseOptions =
1459+ ( MarkdownParseOptions.ParseCodeAsOther
1460+ ||| MarkdownParseOptions.ParseNonCodeAsOther))
1461+ |> Literate.ToPynb
1462+ |> ParsePynb.pynbStringToMarkdown
1463+ mdOut |> shouldEqual mdIn
14361464
14371465[<Test>]
14381466let ``Script output is exactly right`` () =
You can’t perform that action at this time.
0 commit comments