diff --git a/Frontmatter.Test/LineEndingTests.cs b/Frontmatter.Test/LineEndingTests.cs index 8f6f77c..063287f 100644 --- a/Frontmatter.Test/LineEndingTests.cs +++ b/Frontmatter.Test/LineEndingTests.cs @@ -83,4 +83,39 @@ public void RemoveFrontmatter_KeepsTheInputLineEnding(string nl) Assert.AreEqual(Lines(nl, "line1", "line2"), result); } + + [TestMethod] + [DataRow("\r\n", DisplayName = "CRLF")] + [DataRow("\n", DisplayName = "LF")] + [DataRow("\r", DisplayName = "CR")] + public void ExtractBody_DropsBlankLinesAfterTheHeader_ForEveryLineEnding(string nl) + { + string input = Lines(nl, "---", "title: x", "---", string.Empty, string.Empty, "Body"); + + Assert.AreEqual("Body", Frontmatter.ExtractBody(input)); + } + + [TestMethod] + [DataRow("\r\n", DisplayName = "CRLF")] + [DataRow("\n", DisplayName = "LF")] + [DataRow("\r", DisplayName = "CR")] + public void RemoveFrontmatter_DropsBlankLinesAfterTheHeader_ForEveryLineEnding(string nl) + { + string input = Lines(nl, "---", "title: x", "---", string.Empty, string.Empty, "Body"); + + Assert.AreEqual(Lines(nl, "Body"), Frontmatter.RemoveFrontmatter(input)); + } + + [TestMethod] + [DataRow("\r\n", DisplayName = "CRLF")] + [DataRow("\n", DisplayName = "LF")] + [DataRow("\r", DisplayName = "CR")] + public void ReplaceFrontmatter_DropsBlankLinesAfterTheHeader_ForEveryLineEnding(string nl) + { + string input = Lines(nl, "---", "title: x", "---", string.Empty, string.Empty, "Body"); + + string result = Frontmatter.ReplaceFrontmatter(input, new Dictionary { ["title"] = "y" }); + + Assert.AreEqual(Lines(nl, "---", "title: y", "---", "Body"), result); + } } diff --git a/Frontmatter/Frontmatter.cs b/Frontmatter/Frontmatter.cs index 2f9b62a..df26925 100644 --- a/Frontmatter/Frontmatter.cs +++ b/Frontmatter/Frontmatter.cs @@ -524,7 +524,7 @@ private static string TrimBody(string body) for (int i = start; i < body.Length; i++) { char c = body[i]; - if (c == '\n') + if (c is '\n' or '\r') { start = i + 1; }