A platform for community discussion. Free, open, simple.
FIX: skip <br> inside <p> if next character is \n
Vinoth Kannan87b53e170be4
diff --git a/Gemfile.lock b/Gemfile.lockindex 13faf684880..283b5ccdee4 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -572,4 +572,4 @@ DEPENDENCIESwebpushBUNDLED WITH- 1.17.3+ 2.0.1diff --git a/lib/html_to_markdown.rb b/lib/html_to_markdown.rbindex b16f647183c..57a95799601 100644--- a/lib/html_to_markdown.rb+++ b/lib/html_to_markdown.rb@@ -185,6 +185,7 @@ class HtmlToMarkdowndef visit_br(node)return if node.previous_sibling.nil? && EMPHASIS.include?(node.parent.name)+ return if node.parent.name == "p" && (node.next_sibling&.text || "").start_with?("\n")@stack[-1].markdown << "\n"enddiff --git a/spec/components/html_to_markdown_spec.rb b/spec/components/html_to_markdown_spec.rbindex 1070cf07b51..d736a2997e9 100644--- a/spec/components/html_to_markdown_spec.rb+++ b/spec/components/html_to_markdown_spec.rb@@ -103,6 +103,10 @@ describe HtmlToMarkdown doexpect(html_to_markdown("Before<br>Inside<br>After")).to eq("Before\nInside\nAfter")end+ it "skips <br> inside <p> if next character is \n" do+ expect(html_to_markdown("<p>Before<br>\nInside<br>After</p>")).to eq("Before\nInside\nAfter")+ end+it "converts <hr>" doexpect(html_to_markdown("Before<hr>Inside<hr>After")).to eq("Before\n\n---\n\nInside\n\n---\n\nAfter")end