Skip to content

Commit

Permalink
Fix GH-356
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticmind committed Jan 3, 2024
1 parent be30b67 commit 16396cf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the 1~~st~~ sentence to t~~est the strikethrough tag conversion~~
7 changes: 7 additions & 0 deletions src/ReverseMarkdown.Test/ConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,5 +1327,12 @@ public Task When_Anchor_Text_with_Underscore_Do_Not_Escape()
var html = $"This a sample <strong>paragraph</strong> from <a href=\"https://www.w3schools.com/html/mov_bbb.mp4\">https://www.w3schools.com/html/mov_bbb.mp4</a>";
return CheckConversion(html);
}

[Fact]
public Task When_Strikethrough_And_Nested_Strikethrough()
{
var html = $"This is the 1<s>st</s> sentence to t<del>e<strike>s</strike></strike>t the strikethrough tag conversion";
return CheckConversion(html);
}
}
}
3 changes: 3 additions & 0 deletions src/ReverseMarkdown.Test/ReverseMarkdown.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@
<None Update="ConverterTests.When_Anchor_Text_with_Underscore_Do_Not_Escape.verified.md">
<DependentUpon>ConverterTests.WhenThereIsSingleAsteriskInText_ThenConvertToMarkdownEscapedAsterisk.verified.md</DependentUpon>
</None>
<None Update="ConverterTests.When_Strikethrough_And_Nested_Strikethrough.verified.md">
<DependentUpon>ConverterTests.WhenThereIsUnorderedListAndBulletIsAsterisk_ThenConvertToMarkdownList.verified.md</DependentUpon>
</None>
</ItemGroup>
</Project>
33 changes: 33 additions & 0 deletions src/ReverseMarkdown/Converters/S.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Linq;
using HtmlAgilityPack;

namespace ReverseMarkdown.Converters
{
public class S : ConverterBase
{
public S(Converter converter) : base(converter)
{
Converter.Register("s", this);
Converter.Register("del", this);
Converter.Register("strike", this);
}

public override string Convert(HtmlNode node)
{
var content = TreatChildren(node);
if (string.IsNullOrEmpty(content) || AlreadyStrikethrough(node))
{
return content;
}
else
{
return $"~~{content.Trim().Chomp(all:true)}~~";
}
}

private static bool AlreadyStrikethrough(HtmlNode node)
{
return node.Ancestors("s").Any() || node.Ancestors("del").Any() || node.Ancestors("strike").Any();
}
}
}

0 comments on commit 16396cf

Please sign in to comment.