[backend/libmfm] Fix code block serialization

This commit is contained in:
Laura Hausmann 2024-04-28 23:46:05 +02:00
parent 50cfc6df92
commit 5599805196
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 24 additions and 1 deletions

View file

@ -17,7 +17,7 @@ public static class MfmSerializer
{
result.Append($"```{mfmCodeBlockNode.Language?.Value ?? ""}\n");
result.Append(mfmCodeBlockNode.Code);
result.Append("```");
result.Append("\n```");
break;
}
case MfmMathBlockNode mfmMathBlockNode:

View file

@ -93,6 +93,29 @@ public class MfmTests
MfmSerializer.Serialize(res).Should().BeEquivalentTo(input);
}
[TestMethod]
public void TestCodeBlock()
{
const string input = """
test 123
```
this is a code block
```
test 123
""";
List<MfmNode> expected =
[
new MfmTextNode("test 123\n"),
new MfmCodeBlockNode("this is a code block", null),
new MfmTextNode("\ntest 123")
];
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()
{