Skip to content

Commit 16396cf

Browse files
committed
Fix GH-356
1 parent be30b67 commit 16396cf

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is the 1~~st~~ sentence to t~~est the strikethrough tag conversion~~

src/ReverseMarkdown.Test/ConverterTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,5 +1327,12 @@ public Task When_Anchor_Text_with_Underscore_Do_Not_Escape()
13271327
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>";
13281328
return CheckConversion(html);
13291329
}
1330+
1331+
[Fact]
1332+
public Task When_Strikethrough_And_Nested_Strikethrough()
1333+
{
1334+
var html = $"This is the 1<s>st</s> sentence to t<del>e<strike>s</strike></strike>t the strikethrough tag conversion";
1335+
return CheckConversion(html);
1336+
}
13301337
}
13311338
}

src/ReverseMarkdown.Test/ReverseMarkdown.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@
4242
<None Update="ConverterTests.When_Anchor_Text_with_Underscore_Do_Not_Escape.verified.md">
4343
<DependentUpon>ConverterTests.WhenThereIsSingleAsteriskInText_ThenConvertToMarkdownEscapedAsterisk.verified.md</DependentUpon>
4444
</None>
45+
<None Update="ConverterTests.When_Strikethrough_And_Nested_Strikethrough.verified.md">
46+
<DependentUpon>ConverterTests.WhenThereIsUnorderedListAndBulletIsAsterisk_ThenConvertToMarkdownList.verified.md</DependentUpon>
47+
</None>
4548
</ItemGroup>
4649
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Linq;
2+
using HtmlAgilityPack;
3+
4+
namespace ReverseMarkdown.Converters
5+
{
6+
public class S : ConverterBase
7+
{
8+
public S(Converter converter) : base(converter)
9+
{
10+
Converter.Register("s", this);
11+
Converter.Register("del", this);
12+
Converter.Register("strike", this);
13+
}
14+
15+
public override string Convert(HtmlNode node)
16+
{
17+
var content = TreatChildren(node);
18+
if (string.IsNullOrEmpty(content) || AlreadyStrikethrough(node))
19+
{
20+
return content;
21+
}
22+
else
23+
{
24+
return $"~~{content.Trim().Chomp(all:true)}~~";
25+
}
26+
}
27+
28+
private static bool AlreadyStrikethrough(HtmlNode node)
29+
{
30+
return node.Ancestors("s").Any() || node.Ancestors("del").Any() || node.Ancestors("strike").Any();
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)