diff --git a/src/ReverseMarkdown.Test/ConverterTests.When_Sup_And_Nested_Sup.md b/src/ReverseMarkdown.Test/ConverterTests.When_Sup_And_Nested_Sup.md new file mode 100644 index 0000000..b81145b --- /dev/null +++ b/src/ReverseMarkdown.Test/ConverterTests.When_Sup_And_Nested_Sup.md @@ -0,0 +1 @@ +This is the 1^st^ sentence to t^es^t the sup tag conversion \ No newline at end of file diff --git a/src/ReverseMarkdown.Test/ConverterTests.cs b/src/ReverseMarkdown.Test/ConverterTests.cs index c51949a..18ad0ab 100644 --- a/src/ReverseMarkdown.Test/ConverterTests.cs +++ b/src/ReverseMarkdown.Test/ConverterTests.cs @@ -1311,5 +1311,12 @@ public Task WhenTableHeadingWithAlignmentStyles_ThenTableHeaderShouldHaveProperA $"
Col1Col2Col2
123
"; return CheckConversion(html); } + + [Fact] + public Task When_Sup_And_Nested_Sup() + { + var html = $"This is the 1st sentence to test the sup tag conversion"; + return CheckConversion(html); + } } } diff --git a/src/ReverseMarkdown/Converters/Sup.cs b/src/ReverseMarkdown/Converters/Sup.cs new file mode 100644 index 0000000..b7599da --- /dev/null +++ b/src/ReverseMarkdown/Converters/Sup.cs @@ -0,0 +1,31 @@ +using System.Linq; +using HtmlAgilityPack; + +namespace ReverseMarkdown.Converters +{ + public class Sup : ConverterBase + { + public Sup(Converter converter) : base(converter) + { + Converter.Register("sup", this); + } + + public override string Convert(HtmlNode node) + { + var content = TreatChildren(node); + if (string.IsNullOrEmpty(content) || AlreadySup(node)) + { + return content; + } + else + { + return $"^{content.Trim().Chomp(all:true)}^"; + } + } + + private static bool AlreadySup(HtmlNode node) + { + return node.Ancestors("sup").Any(); + } + } +}