Skip to content

Commit

Permalink
Fix GH-393 regression with mixed new line characters
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticmind committed Jun 29, 2024
1 parent 8329d3e commit 738bd5f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This is regular text

This is HTML:

* Line 1
* Line 2
* Line 3 has an unknown tag
8 changes: 8 additions & 0 deletions src/ReverseMarkdown.Test/ConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,5 +1376,13 @@ public Task Bug391_AnchorTagUnnecessarilyIndented()

return CheckConversion(html, config);
}

[Fact]
public Task Bug393_RegressionWithVaryingNewLines()
{
const string html = "This is regular text\r\n<p class=\"c1\">This is HTML: <ul><li>Line 1</li><li>Line 2</li><li><mark>Line 3 has an unknown tag</mark></li></ul></p>";
var config = new Config { UnknownTags = Config.UnknownTagsOption.Bypass, ListBulletChar = '*' };
return CheckConversion(html, config);
}
}
}
3 changes: 3 additions & 0 deletions src/ReverseMarkdown.Test/ReverseMarkdown.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
</None>
<None Update="ConverterTests.Bug391_AnchorTagUnnecessarilyIndented.verified.md">
<DependentUpon>ConverterTests.WhenThereIsSingleAsteriskInText_ThenConvertToMarkdownEscapedAsterisk.verified.md</DependentUpon>
</None>
<None Update="ConverterTests.Bug393_RegressionWithVaryingNewLines.verified.md">
<DependentUpon>ConverterTests.WhenThereIsPreTag_ThenConvertToMarkdownPre.verified.md</DependentUpon>
</None>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/ReverseMarkdown/StringUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public static string EmphasizeContentWhitespaceGuard(this string content, string

public static string FixMultipleNewlines(this string markdown)
{
var normalizedMarkdown = Regex.Replace(markdown, @"\r\n|\r|\n", "\n");
var pattern = @"\n{2,}";
var normalizedMarkdown = Regex.Replace(markdown, @"\r\n|\r|\n", Environment.NewLine);
var pattern = $"{Environment.NewLine}{{2,}}";
return Regex.Replace(normalizedMarkdown, pattern, Environment.NewLine + Environment.NewLine);
}

Expand Down

0 comments on commit 738bd5f

Please sign in to comment.