Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="10.7.0" />
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="10.7.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.7.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="ReverseMarkdown" Version="5.4.0" />
<PackageVersion Include="Terminal.Gui" Version="2.4.16" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="10.0.300" />
<PackageVersion Include="ReverseMarkdown" Version="6.1.0" />
<PackageVersion Include="Terminal.Gui" Version="2.4.17" />
<PackageVersion Include="Tomlyn" Version="2.10.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
<PackageVersion Include="xunit.v3" Version="3.2.2" />
Expand Down
6 changes: 4 additions & 2 deletions src/Cobalt.Core/Text/HtmlMarkdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public static partial class HtmlMarkdown
{
private static readonly ReverseMarkdown.Converter ToMd = new(new ReverseMarkdown.Config
{
UnknownTags = ReverseMarkdown.Config.UnknownTagsOption.PassThrough,
// ReverseMarkdown 6 moved these onto nested option objects (the old flat
// UnknownTags/RemoveComments are [Obsolete]); GithubFlavored stayed top-level.
Tags = { Unknown = ReverseMarkdown.Config.UnknownTagsOption.PassThrough },
GithubFlavored = true,
RemoveComments = true,
Formatting = { RemoveComments = true },
});

private static readonly MarkdownPipeline MdPipeline =
Expand Down
12 changes: 12 additions & 0 deletions tests/Cobalt.Core.Tests/Text/HtmlMarkdownTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ public void Empty_And_Null_Html_Become_Empty_Markdown()
Assert.Equal("", HtmlMarkdown.ToMarkdown(""));
}

[Fact]
public void Html_To_Markdown_Strips_Comments_And_Passes_Unknown_Tags_Through()
{
// Pins the two options carried across the ReverseMarkdown 6 config API migration:
// Formatting.RemoveComments strips HTML comments, and Tags.Unknown = PassThrough keeps an
// unsupported tag verbatim (so a lossy round-trip stays visible) rather than dropping it.
var md = HtmlMarkdown.ToMarkdown("<p>keep<!-- drop me --> this</p><foo>inner text</foo>");

Assert.DoesNotContain("drop me", md); // RemoveComments strips the comment
Assert.Contains("<foo>inner text</foo>", md); // PassThrough keeps the unknown tag as-is
}

[Fact]
public void Simple_Content_Round_Trips_Cleanly()
{
Expand Down