-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be30b67
commit 16396cf
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...own.Test/ConverterTests.When_Strikethrough_And_Nested_Strikethrough.verified.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |