From 7b76c5a3e5102093ca237f0b9ce90dacbea448b9 Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Fri, 2 Aug 2024 21:25:26 +0100 Subject: [PATCH] Fix issue where HTML was allowed in headings Fixes #114 --- .../inspectionProfiles/Project_Default.xml | 36 ++ CHANGELOG.md | 4 + .../Replacement/AnchorTagReplacer.cs | 19 +- .../Replacement/HeadingTagReplacer.cs | 14 +- src/Html2Markdown/Replacement/HtmlParser.cs | 23 ++ ...ConverterTest.Convert_Bug_114.verified.txt | 43 +++ ...ConverterTest.Convert_Bug_114.verified.txt | 43 +++ .../MarkdownSchemeConverterTest.cs | 323 +++++++++++------- 8 files changed, 365 insertions(+), 140 deletions(-) create mode 100644 .idea/.idea.Html2Markdown/.idea/inspectionProfiles/Project_Default.xml create mode 100644 test/Html2Markdown.Test/CommonMarkSchemeConverterTest.Convert_Bug_114.verified.txt create mode 100644 test/Html2Markdown.Test/MarkdownSchemeConverterTest.Convert_Bug_114.verified.txt diff --git a/.idea/.idea.Html2Markdown/.idea/inspectionProfiles/Project_Default.xml b/.idea/.idea.Html2Markdown/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..3645830f --- /dev/null +++ b/.idea/.idea.Html2Markdown/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index b9d2971a..c3986629 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fixed issue where HTML was allowed in headings + ## [6.2.3.6] - 2024-08-02 ### Fixed diff --git a/src/Html2Markdown/Replacement/AnchorTagReplacer.cs b/src/Html2Markdown/Replacement/AnchorTagReplacer.cs index 8a1b0940..65db1787 100644 --- a/src/Html2Markdown/Replacement/AnchorTagReplacer.cs +++ b/src/Html2Markdown/Replacement/AnchorTagReplacer.cs @@ -1,17 +1,16 @@ -namespace Html2Markdown.Replacement +namespace Html2Markdown.Replacement; + +/// +/// Replaces an anchor tag with the link text and the link URL in Markdown format. +/// +public class AnchorTagReplacer : CustomReplacer { /// - /// Replaces an anchor tag with the link text and the link URL in Markdown format. + /// Initializes a new instance of the class. + /// Sets the custom action to replace anchor tags with Markdown formatted links. /// - public class AnchorTagReplacer : CustomReplacer + public AnchorTagReplacer() { - /// - /// Initializes a new instance of the class. - /// Sets the custom action to replace anchor tags with Markdown formatted links. - /// - public AnchorTagReplacer() - { CustomAction = HtmlParser.ReplaceAnchor; } - } } \ No newline at end of file diff --git a/src/Html2Markdown/Replacement/HeadingTagReplacer.cs b/src/Html2Markdown/Replacement/HeadingTagReplacer.cs index 0c5213f3..3645f0ae 100644 --- a/src/Html2Markdown/Replacement/HeadingTagReplacer.cs +++ b/src/Html2Markdown/Replacement/HeadingTagReplacer.cs @@ -3,7 +3,7 @@ /// /// Replaces the HTML heading tag with its Markdown equivalent. /// -public class HeadingTagReplacer : CompositeReplacer +public class HeadingTagReplacer : CustomReplacer { /// /// Initializes a new instance of the class. @@ -14,16 +14,6 @@ public HeadingTagReplacer(Heading heading) { var headingNumber = (int) heading; - AddReplacer(new PatternReplacer - { - Pattern = $"", - Replacement = Environment.NewLine + Environment.NewLine - }); - - AddReplacer(new PatternReplacer - { - Pattern = $"]*>", - Replacement = Environment.NewLine + Environment.NewLine + new string('#', headingNumber) + " " - }); + CustomAction = html => HtmlParser.ReplaceHeading(html, headingNumber); } } \ No newline at end of file diff --git a/src/Html2Markdown/Replacement/HtmlParser.cs b/src/Html2Markdown/Replacement/HtmlParser.cs index f5ee4853..cc051ef5 100644 --- a/src/Html2Markdown/Replacement/HtmlParser.cs +++ b/src/Html2Markdown/Replacement/HtmlParser.cs @@ -273,6 +273,27 @@ internal static string ReplaceEntities(string html) } internal static string ReplaceParagraph(string html) => ReplaceParagraph(html, false); + + internal static string ReplaceHeading(string html, int headingNumber) + { + var tag = $"h{headingNumber}"; + var doc = GetHtmlDocument(html); + var nodes = doc.DocumentNode.SelectNodes($"//{tag}"); + + if (nodes is null) return html; + + nodes.ToList().ForEach(node => + { + var text = node.InnerHtml; + var htmlRemoved = HtmlTags().Replace(text, ""); + var markdown = Spaces().Replace(htmlRemoved, " "); + markdown = markdown.Replace(Environment.NewLine, " "); + markdown = Environment.NewLine + Environment.NewLine + new string('#', headingNumber) + " " + markdown + Environment.NewLine + Environment.NewLine; + ReplaceNode(node, markdown); + }); + + return doc.DocumentNode.OuterHtml; + } private static string ReplaceParagraph(string html, bool nestedIntoList) { @@ -346,4 +367,6 @@ private static void ReplaceNode(HtmlNode node, string markdown) private static partial Regex FinalCrLf(); [GeneratedRegex(@"<\s*?/?\s*?br\s*?>")] private static partial Regex BreakTag(); + [GeneratedRegex(@"<[^>]+>")] + private static partial Regex HtmlTags(); } \ No newline at end of file diff --git a/test/Html2Markdown.Test/CommonMarkSchemeConverterTest.Convert_Bug_114.verified.txt b/test/Html2Markdown.Test/CommonMarkSchemeConverterTest.Convert_Bug_114.verified.txt new file mode 100644 index 00000000..04d35d67 --- /dev/null +++ b/test/Html2Markdown.Test/CommonMarkSchemeConverterTest.Convert_Bug_114.verified.txt @@ -0,0 +1,43 @@ +## Support + +This project will currently convert the following HTML tags:- + +* `` +* `` +* `` +* `` +* `` +* `
` +* `` +* `

` +* `

` +* `

` +* `

` +* `

` +* `
` +* `
` +* `` +* `
` +* `

` +* `

`
+*   `
    ` +* `
      ` + +## [](https://github.com/baynezy/Html2Markdown#installing-via-nuget)Installing via NuGet + +[![NuGet version](https://camo.githubusercontent.com/2ee778ef534fdd413d5055d3202813398f39235a3d60b13974d43bc1bf1523a1/68747470733a2f2f62616467652e667572792e696f2f6e752f48746d6c324d61726b646f776e2e737667)](http://badge.fury.io/nu/Html2Markdown) +
      + + Install-Package Html2Markdown +
      + +## [](https://github.com/baynezy/Html2Markdown#usage)Usage + +### [](https://github.com/baynezy/Html2Markdown#strings)Strings + +
      + +var html = "Something to convert"; + var converter = new Converter(); + var markdown = converter.Convert(html); +
      \ No newline at end of file diff --git a/test/Html2Markdown.Test/MarkdownSchemeConverterTest.Convert_Bug_114.verified.txt b/test/Html2Markdown.Test/MarkdownSchemeConverterTest.Convert_Bug_114.verified.txt new file mode 100644 index 00000000..04d35d67 --- /dev/null +++ b/test/Html2Markdown.Test/MarkdownSchemeConverterTest.Convert_Bug_114.verified.txt @@ -0,0 +1,43 @@ +## Support + +This project will currently convert the following HTML tags:- + +* `
      ` +* `` +* `` +* `` +* `` +* `
      ` +* `` +* `

      ` +* `

      ` +* `

      ` +* `

      ` +* `

      ` +* `
      ` +* `
      ` +* `` +* `
      ` +* `

      ` +* `

      `
      +*   `
        ` +* `
          ` + +## [](https://github.com/baynezy/Html2Markdown#installing-via-nuget)Installing via NuGet + +[![NuGet version](https://camo.githubusercontent.com/2ee778ef534fdd413d5055d3202813398f39235a3d60b13974d43bc1bf1523a1/68747470733a2f2f62616467652e667572792e696f2f6e752f48746d6c324d61726b646f776e2e737667)](http://badge.fury.io/nu/Html2Markdown) +
          + + Install-Package Html2Markdown +
          + +## [](https://github.com/baynezy/Html2Markdown#usage)Usage + +### [](https://github.com/baynezy/Html2Markdown#strings)Strings + +
          + +var html = "Something to convert"; + var converter = new Converter(); + var markdown = converter.Convert(html); +
          \ No newline at end of file diff --git a/test/Html2Markdown.Test/MarkdownSchemeConverterTest.cs b/test/Html2Markdown.Test/MarkdownSchemeConverterTest.cs index 1492d7c4..680c8328 100644 --- a/test/Html2Markdown.Test/MarkdownSchemeConverterTest.cs +++ b/test/Html2Markdown.Test/MarkdownSchemeConverterTest.cs @@ -11,7 +11,7 @@ public class MarkdownSchemeConverterTest [Test] public void Converter_WhenProvidingMarkdownAsACustomScheme_ThenShouldConvertEquivalentlyToNoScheme() { - const string html = @"So this is
          a link. Convert it"; + const string html = """So this is a link. Convert it"""; var scheme = new Markdown(); @@ -28,7 +28,7 @@ public void Converter_WhenProvidingMarkdownAsACustomScheme_ThenShouldConvertEqui [Test] public Task Convert_WhenThereAreHtmlLinks_ThenConvertToMarkDownLinks() { - const string html = @"So this is a link. Convert it"; + const string html = """So this is a link. Convert it"""; return CheckConversion(html); } @@ -36,7 +36,7 @@ public Task Convert_WhenThereAreHtmlLinks_ThenConvertToMarkDownLinks() [Test] public Task Convert_WhenThereAreHtmlLinksWithAttributesAfterTheHref_ThenConvertToMarkDownLink() { - const string html = @"So this is a link. Convert it"; + const string html = """So this is a link. Convert it"""; return CheckConversion(html); } @@ -44,7 +44,7 @@ public Task Convert_WhenThereAreHtmlLinksWithAttributesAfterTheHref_ThenConvertT [Test] public Task Convert_WhenThereAreHtmlLinksWithAttributesBeforeTheHref_ThenConvertToMarkDownLink() { - const string html = @"So this is a link. Convert it"; + const string html = """So this is a link. Convert it"""; return CheckConversion(html); } @@ -52,7 +52,7 @@ public Task Convert_WhenThereAreHtmlLinksWithAttributesBeforeTheHref_ThenConvert [Test] public Task Convert_WhenThereAreHtmlLinksWithTitleAttributeAfterTheHref_ThenConvertToMarkDownLink() { - const string html = @"So this is a link. Convert it"; + const string html = """So this is a link. Convert it"""; return CheckConversion(html); } @@ -60,7 +60,7 @@ public Task Convert_WhenThereAreHtmlLinksWithTitleAttributeAfterTheHref_ThenConv [Test] public Task Convert_WhenThereAreHtmlLinksWithTitleAttributeBeforeTheHref_ThenConvertToMarkDownLink() { - const string html = @"So this is a link. Convert it"; + const string html = """So this is a link. Convert it"""; return CheckConversion(html); } @@ -68,7 +68,7 @@ public Task Convert_WhenThereAreHtmlLinksWithTitleAttributeBeforeTheHref_ThenCon [Test] public Task Convert_WhenThereAreMultipleHtmlLinks_ThenConvertThemToMarkDownLinks() { - const string html = @"So this is a link and so is this. Convert them"; + const string html = """So this is a link and so is this. Convert them"""; return CheckConversion(html); } @@ -76,7 +76,7 @@ public Task Convert_WhenThereAreMultipleHtmlLinks_ThenConvertThemToMarkDownLinks [Test] public Task Convert_WhenThereAreEmptyLinks_ThenRemoveThemFromResult() { - const string html = @"So this is and so is this. Convert them"; + const string html = """So this is and so is this. Convert them"""; return CheckConversion(html); } @@ -144,7 +144,7 @@ public Task Convert_WhenThereAreBoldTags_ThenConvertToMarkDownDoubleAsterisks() [Test] public Task Convert_WhenThereIsABoldTagWithProperties_ThenConvertToMarkDownDoubleAsterisks() { - const string html = @"So this text is bold. Convert it."; + const string html = """So this text is bold. Convert it."""; return CheckConversion(html); } @@ -152,7 +152,7 @@ public Task Convert_WhenThereIsABoldTagWithProperties_ThenConvertToMarkDownDoubl [Test] public Task Convert_WhenThereIsAStrongTagWithProperties_ThenConvertToMarkDownDoubleAsterisks() { - const string html = @"So this text is bold. Convert it."; + const string html = """So this text is bold. Convert it."""; return CheckConversion(html); } @@ -252,12 +252,14 @@ public Task Convert_WhenThereAreCodeTags_ThenReplaceWithBackTick() [Test] public Task Convert_WhenThereMultilineCodeTags_ThenReplaceWithMultilineMarkdownBlock001() { - const string html = @"So this text has multiline code. - -<p> - Some code we are looking at -</p> -"; + const string html = """ + So this text has multiline code. + + <p> + Some code we are looking at + </p> + + """; return CheckConversion(html); } @@ -265,12 +267,14 @@ Some code we are looking at [Test] public Task Convert_WhenThereMultilineCodeTags_ThenReplaceWithMultilineMarkdownBlock002() { - const string html = @"So this text has multiline code. - - <p> - Some code we are looking at - </p> -"; + const string html = """ + So this text has multiline code. + + <p> + Some code we are looking at + </p> + + """; return CheckConversion(html); } @@ -279,12 +283,14 @@ Some code we are looking at [Test] public Task Convert_WhenThereMultilineCodeTags_ThenReplaceWithMultilineMarkdownBlock003() { - const string html = @" - class solution {
          - int i;
          - string name = “name”;
          - } -
          "; + const string html = """ + + class solution {
          + int i;
          + string name = “name”;
          + } +
          + """; return CheckConversion(html); } @@ -344,7 +350,7 @@ public Task Convert_WhenThereAreH6Tags_ThenReplaceWithMarkDownHeader() [Test] public Task Convert_WhenThereAreH1TagsWithAttributes_ThenReplaceWithMarkDownHeader() { - const string html = @"This code has a

          header

          . Convert it."; + const string html = """This code has a

          header

          . Convert it."""; return CheckConversion(html); } @@ -353,7 +359,7 @@ public Task Convert_WhenThereAreH1TagsWithAttributes_ThenReplaceWithMarkDownHead [Test] public Task Convert_WhenThereAreH2TagsWithAttributes_ThenReplaceWithMarkDownHeader() { - const string html = @"This code has a

          header

          . Convert it."; + const string html = """This code has a

          header

          . Convert it."""; return CheckConversion(html); } @@ -361,7 +367,7 @@ public Task Convert_WhenThereAreH2TagsWithAttributes_ThenReplaceWithMarkDownHead [Test] public Task Convert_WhenThereAreH3TagsWithAttributes_ThenReplaceWithMarkDownHeader() { - const string html = @"This code has a

          header

          . Convert it."; + const string html = """This code has a

          header

          . Convert it."""; return CheckConversion(html); } @@ -369,7 +375,7 @@ public Task Convert_WhenThereAreH3TagsWithAttributes_ThenReplaceWithMarkDownHead [Test] public Task Convert_WhenThereAreH4TagsWithAttributes_ThenReplaceWithMarkDownHeader() { - const string html = @"This code has a

          header

          . Convert it."; + const string html = """This code has a

          header

          . Convert it."""; return CheckConversion(html); } @@ -377,7 +383,7 @@ public Task Convert_WhenThereAreH4TagsWithAttributes_ThenReplaceWithMarkDownHead [Test] public Task Convert_WhenThereAreH5TagsWithAttributes_ThenReplaceWithMarkDownHeader() { - const string html = @"This code has a
          header
          . Convert it."; + const string html = """This code has a
          header
          . Convert it."""; return CheckConversion(html); } @@ -385,7 +391,7 @@ public Task Convert_WhenThereAreH5TagsWithAttributes_ThenReplaceWithMarkDownHead [Test] public Task Convert_WhenThereAreH6TagsWithAttributes_ThenReplaceWithMarkDownHeader() { - const string html = @"This code has a
          header
          . Convert it."; + const string html = """This code has a
          header
          . Convert it."""; return CheckConversion(html); } @@ -413,10 +419,12 @@ public Task Convert_WhenThereIsABlockquoteTagWithNestedHtml_ThenReplaceWithMarkD [Test] public Task Convert_WhenThereIsAMultilineBlockquoteTag_ThenReplaceWithMarkDownBlockQuote() { - const string html = @"
          -

          “Ao estipular seus objetivos, mire na Lua; pois mesmo que aconteça de você não alcançá-los, ainda estará entre as estrelas!”
          - — Dr. Lair Ribeiro

          -
          "; + const string html = """ +
          +

          “Ao estipular seus objetivos, mire na Lua; pois mesmo que aconteça de você não alcançá-los, ainda estará entre as estrelas!”
          + — Dr. Lair Ribeiro

          +
          + """; return CheckConversion(html); } @@ -424,7 +432,7 @@ public Task Convert_WhenThereIsAMultilineBlockquoteTag_ThenReplaceWithMarkDownBl [Test] public Task Convert_WhenThereIsABlockquoteTagWithAttributes_ThenReplaceWithMarkDownBlockQuote() { - const string html = @"This code has a
          blockquote
          . Convert it."; + const string html = """This code has a
          blockquote
          . Convert it."""; return CheckConversion(html); } @@ -444,7 +452,7 @@ public Task Convert_WhenThereAreParagraphTags_ThenReplaceWithDoubleLineBreakBefo [Test] public Task Convert_WhenThereAreParagraphTagsWithAttributes_ThenReplaceWithDoubleLineBreakBeforeAndOneAfter() { - const string html = @"This code has no markup.

          This code is in a paragraph.

          Convert it!"; + const string html = """This code has no markup.

          This code is in a paragraph.

          Convert it!"""; return CheckConversion(html); } @@ -452,11 +460,13 @@ public Task Convert_WhenThereAreParagraphTagsWithAttributes_ThenReplaceWithDoubl [Test] public Task Convert_WhenThereAreParagraphTagsWithNewLinesInThem_ThenReplaceWithMarkdownParagraphButNoBreakTags() { - const string html = @"

          - text - text - text -

          "; + const string html = """ +

          + text + text + text +

          + """; return CheckConversion(html); } @@ -484,7 +494,7 @@ public Task Convert_WhenThereAreHorizontalRuleTagsWithWhiteSpace_ThenReplaceWith [Test] public Task Convert_WhenThereAreHorizontalRuleTagsWithAttributes_ThenReplaceWithMarkDownHorizontalRule() { - const string html = @"This code is seperated by a horizontal rule.
          Convert it!"; + const string html = """This code is seperated by a horizontal rule.
          Convert it!"""; return CheckConversion(html); } @@ -504,7 +514,7 @@ public Task Convert_WhenThereAreHorizontalRuleTagsThatAreNonSelfClosing_ThenRepl [Test] public Task Convert_WhenThereAreImgTags_ThenReplaceWithMarkdownImage() { - const string html = @"This code is with and image Convert it!"; + const string html = """This code is with and image something Convert it!"""; return CheckConversion(html); } @@ -512,7 +522,7 @@ public Task Convert_WhenThereAreImgTags_ThenReplaceWithMarkdownImage() [Test] public Task Convert_WhenThereAreImgTagsWithoutATitle_ThenReplaceWithMarkdownImage() { - const string html = @"This code is with an image Convert it!"; + const string html = """This code is with an image something Convert it!"""; return CheckConversion(html); } @@ -524,8 +534,10 @@ public Task Convert_WhenThereAreImgTagsWithoutATitle_ThenReplaceWithMarkdownImag [Test] public Task Convert_WhenThereArePreTags_ThenReplaceWithMarkdownPre() { - const string html = @"This code is with a pre tag
          -	Predefined text
          "; + const string html = """ + This code is with a pre tag
          +		                    	Predefined text
          + """; return CheckConversion(html); } @@ -533,8 +545,10 @@ public Task Convert_WhenThereArePreTags_ThenReplaceWithMarkdownPre() [Test] public Task Convert_WhenThereAreOtherTagsNestedInThePreTag_ThenReplaceWithMarkdownPre() { - const string html = @"
          Install-Package Html2Markdown
          -
          "; + const string html = """ +
          Install-Package Html2Markdown
          +		                    
          + """; return CheckConversion(html); } @@ -542,16 +556,18 @@ public Task Convert_WhenThereAreOtherTagsNestedInThePreTag_ThenReplaceWithMarkdo [Test] public Task Convert_WhenThereAreMultiplePreTags_ThenReplaceWithMarkdownPre() { - const string html = @"

          Installing via NuGet

          + const string html = """ +

          Installing via NuGet

          -
          Install-Package Html2Markdown
          -
          +
          Install-Package Html2Markdown
          +		                    
          -

          Usage

          +

          Usage

          -
          var converter = new Converter();
          -var result = converter.Convert(html);
          -
          "; +
          var converter = new Converter();
          +		                    var result = converter.Convert(html);
          +		                    
          + """; return CheckConversion(html); } @@ -619,17 +635,19 @@ public Task Convert_WhenThereIsAnOrderedListWithNestedParagraphs_ThenReplaceWith [Test] public Task Convert_WhenThereIsAMultilineOrderedListWithNestedParagraphsAndCodeElement_ThenReplaceWithMarkdownLists() { - const string html = @"

          This code is with an ordered list and paragraphs.

          -
            -
          1. Yes, this is a code element

            -
          2. -
          3. No :

            -
              -
            • Some code we are looking at
            • -
            -
          4. -
          -"; + const string html = """ +

          This code is with an ordered list and paragraphs.

          +
            +
          1. Yes, this is a code element

            +
          2. +
          3. No :

            +
              +
            • Some code we are looking at
            • +
            +
          4. +
          + + """; return CheckConversion(html); } @@ -650,8 +668,10 @@ public Task Convert_WhenThereAreMultipleUnorderedLists_ThenReplaceWithMarkdownLi [Test] public Task Convert_WhenThereIsAnHtmlDoctype_ThenRemoveFromResult() { - const string html = @" -Doctypes should be removed"; + const string html = """ + + Doctypes should be removed + """; return CheckConversion(html); } @@ -659,9 +679,11 @@ public Task Convert_WhenThereIsAnHtmlDoctype_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsAnHtmlTag_ThenRemoveFromResult() { - const string html = @" -

          HTML tags should be removed

          -"; + const string html = """ + +

          HTML tags should be removed

          + + """; return CheckConversion(html); } @@ -669,9 +691,11 @@ public Task Convert_WhenThereIsAnHtmlTag_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsAnHtmlTagWithAttributes_ThenRemoveFromResult() { - const string html = @" -

          HTML tags should be removed

          -"; + const string html = """ + +

          HTML tags should be removed

          + + """; return CheckConversion(html); } @@ -679,8 +703,10 @@ public Task Convert_WhenThereIsAnHtmlTagWithAttributes_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsASingleLineComment_ThenRemoveFromResult() { - const string html = @" -

          Comments should be removed

          "; + const string html = """ + +

          Comments should be removed

          + """; return CheckConversion(html); } @@ -688,10 +714,12 @@ public Task Convert_WhenThereIsASingleLineComment_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsAMultiLineComment_ThenRemoveFromResult() { - const string html = @" -

          Comments should be removed

          "; + const string html = """ + +

          Comments should be removed

          + """; return CheckConversion(html); } @@ -699,9 +727,11 @@ a comment [Test] public Task Convert_WhenThereIsAHeadTag_ThenRemoveFromResult() { - const string html = @" -

          HTML tags should be removed

          -"; + const string html = """ + +

          HTML tags should be removed

          + + """; return CheckConversion(html); } @@ -709,9 +739,11 @@ public Task Convert_WhenThereIsAHeadTag_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsAHeadTagWithAttributes_ThenRemoveFromResult() { - const string html = @" -

          HTML tags should be removed

          -"; + const string html = """ + +

          HTML tags should be removed

          + + """; return CheckConversion(html); } @@ -719,8 +751,10 @@ public Task Convert_WhenThereIsAHeadTagWithAttributes_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsAMetaTag_ThenRemoveFromResult() { - const string html = @" -

          Meta tags should be removed

          "; + const string html = """ + +

          Meta tags should be removed

          + """; return CheckConversion(html); } @@ -728,8 +762,10 @@ public Task Convert_WhenThereIsAMetaTag_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsATitleTag_ThenRemoveFromResult() { - const string html = @"Remove me -

          Title tags should be removed

          "; + const string html = """ + Remove me +

          Title tags should be removed

          + """; return CheckConversion(html); } @@ -737,8 +773,10 @@ public Task Convert_WhenThereIsATitleTag_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsATitleTagWithAttributes_ThenRemoveFromResult() { - const string html = @"Remove me -

          Title tags should be removed

          "; + const string html = """ + Remove me +

          Title tags should be removed

          + """; return CheckConversion(html); } @@ -746,8 +784,10 @@ public Task Convert_WhenThereIsATitleTagWithAttributes_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsALinkTag_ThenRemoveFromResult() { - const string html = @" -

          Link tags should be removed

          "; + const string html = """ + +

          Link tags should be removed

          + """; return CheckConversion(html); } @@ -755,9 +795,11 @@ public Task Convert_WhenThereIsALinkTag_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsABodyTag_ThenRemoveFromResult() { - const string html = @" -

          Body tags should be removed

          -"; + const string html = """ + +

          Body tags should be removed

          + + """; return CheckConversion(html); } @@ -765,9 +807,11 @@ public Task Convert_WhenThereIsABodyTag_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsABodyTagWithAttributes_ThenRemoveFromResult() { - const string html = @" -

          Body tags should be removed

          -"; + const string html = """ + +

          Body tags should be removed

          + + """; return CheckConversion(html); } @@ -775,16 +819,18 @@ public Task Convert_WhenThereIsABodyTagWithAttributes_ThenRemoveFromResult() [Test] public Task Convert_WhenThereIsAScriptTag_ThenRemoveFromResult() { - const string html = @" - - - - - -Hello World - -"; + const string html = """ + + + + + + + Hello World + + + """; return CheckConversion(html); } @@ -858,11 +904,13 @@ public Task Convert_ComplexTest_001() [Test] public Task Convert_ComplexTest_002() { - const string html = @"

          Some other HTML

          + const string html = """ +

          Some other HTML

          -
          -

          “Qualquer coisa que possas fazer ou sonhar, podes começá-la. A ousadia encerra em si mesma genialidade, poder e magia.
          Ouse fazer, e o poder lhe será dado!”

          — Johann Wolfgang von Goethe

          -
          "; +
          +

          “Qualquer coisa que possas fazer ou sonhar, podes começá-la. A ousadia encerra em si mesma genialidade, poder e magia.
          Ouse fazer, e o poder lhe será dado!”

          — Johann Wolfgang von Goethe

          +
          + """; return CheckConversion(html); } @@ -894,6 +942,45 @@ public Task Convert_WhenThereIsAParagraphTagAfterAList_ThenThereShouldBeAppropri return CheckConversion(html); } + [Test] + public Task Convert_Bug_114() // https://github.com/baynezy/Html2Markdown/issues/114 + { + const string html = """ + + +

          Support

          This project will currently convert the following HTML tags:-

          +
            +
          • <a>
          • +
          • <strong>
          • +
          • <b>
          • +
          • <em>
          • +
          • <i>
          • +
          • <br>
          • +
          • <code>
          • +
          • <h1>
          • +
          • <h2>
          • +
          • <h3>
          • +
          • <h4>
          • +
          • <h5>
          • +
          • <h6>
          • +
          • <blockquote>
          • +
          • <img>
          • +
          • <hr>
          • +
          • <p>
          • +
          • <pre>
          • +
          • <ul>
          • +
          • <ol>
          • +
          +

          Installing via NuGet

          NuGet version

              Install-Package Html2Markdown

          Usage

          Strings

          var html = "Something to <strong>convert</strong>";
          +		                    var converter = new Converter();
          +		                    var markdown = converter.Convert(html);
          + + + """; + + return CheckConversion(html); + } + #endregion protected virtual Task CheckConversion(string html, IScheme scheme = null)