[parsing] Fix multi line code blocks

This commit is contained in:
Laura Hausmann 2024-04-28 23:59:40 +02:00
parent 5599805196
commit 8ec6607548
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 22 additions and 1 deletions

View file

@ -200,7 +200,7 @@ module private MfmParser =
previousCharSatisfiesNot isNotWhitespace
>>. skipString "```"
>>. opt (many1CharsTill asciiLetter (lookAhead newline))
.>>. (skipNewline >>. manyCharsTill anyChar (skipNewline >>. skipString "```"))
.>>. (skipNewline >>. manyCharsTill anyChar (attempt <| skipNewline >>. skipString "```"))
|>> fun (lang: string option, code: string) -> MfmCodeBlockNode(code, lang) :> MfmNode
let mathNode =

View file

@ -115,6 +115,27 @@ public class MfmTests
res.ToList().Should().Equal(expected, MfmNodeEqual);
MfmSerializer.Serialize(res).Should().BeEquivalentTo(input);
}
[TestMethod]
public void TestCodeBlockMultiLine()
{
const string input = """
```cs
asd
sdf
```
""";
List<MfmNode> expected =
[
new MfmCodeBlockNode("asd\nsdf", "cs")
];
var res = Mfm.parse(input);
AssertionOptions.FormattingOptions.MaxDepth = 100;
res.ToList().Should().Equal(expected, MfmNodeEqual);
MfmSerializer.Serialize(res).Should().BeEquivalentTo(input);
}
[TestMethod]
public void Benchmark()