From 87b53e170be41c6b4356552cdabfdca92170aebd Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Sun, 14 Apr 2019 14:44:54 +0530 Subject: [PATCH] FIX: skip
inside

if next character is \n --- Gemfile.lock | 2 +- lib/html_to_markdown.rb | 1 + spec/components/html_to_markdown_spec.rb | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 13faf684880..283b5ccdee4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -572,4 +572,4 @@ DEPENDENCIES webpush BUNDLED WITH - 1.17.3 + 2.0.1 diff --git a/lib/html_to_markdown.rb b/lib/html_to_markdown.rb index b16f647183c..57a95799601 100644 --- a/lib/html_to_markdown.rb +++ b/lib/html_to_markdown.rb @@ -185,6 +185,7 @@ class HtmlToMarkdown def 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" end diff --git a/spec/components/html_to_markdown_spec.rb b/spec/components/html_to_markdown_spec.rb index 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 do expect(html_to_markdown("Before
Inside
After")).to eq("Before\nInside\nAfter") end + it "skips
inside

if next character is \n" do + expect(html_to_markdown("

Before
\nInside
After

")).to eq("Before\nInside\nAfter") + end + it "converts
" do expect(html_to_markdown("Before
Inside
After")).to eq("Before\n\n---\n\nInside\n\n---\n\nAfter") end