Skip to content

Commit

Permalink
Add support for sup tag conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
francescolf authored and mysticmind committed Dec 11, 2023
1 parent 3529fac commit 1c014c5
Show file tree
Hide file tree
Showing 3 changed files with 39 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^es^t the sup 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 @@ -1311,5 +1311,12 @@ public Task WhenTableHeadingWithAlignmentStyles_ThenTableHeaderShouldHaveProperA
$"<table><tr><th style=\"text-align:left\">Col1</th><th style=\"text-align:center\">Col2</th><th style=\"text-align:right\">Col2</th></tr><tr><td>1</td><td>2</td><td>3</td></tr></table>";
return CheckConversion(html);
}

[Fact]
public Task When_Sup_And_Nested_Sup()
{
var html = $"This is the 1<sup>st</sup> sentence to t<sup>e<sup>s</sup></sup>t the sup tag conversion";
return CheckConversion(html);
}
}
}
31 changes: 31 additions & 0 deletions src/ReverseMarkdown/Converters/Sup.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

0 comments on commit 1c014c5

Please sign in to comment.