From 577af81e76b705b9057edb6083d5c142f2f8ce82 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Mon, 17 Dec 2018 18:39:02 +0100 Subject: [PATCH] FIX: Font tag resulted in wrong email trimming --- lib/html_to_markdown.rb | 4 +++- spec/components/html_to_markdown_spec.rb | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/html_to_markdown.rb b/lib/html_to_markdown.rb index 86ab03dda16..b16f647183c 100644 --- a/lib/html_to_markdown.rb +++ b/lib/html_to_markdown.rb @@ -16,8 +16,10 @@ class HtmlToMarkdown end # If a `
` is within a `` that's invalid, so let's hoist the `
` up + INLINE_ELEMENTS ||= %w{span font} + BLOCK_ELEMENTS ||= %w{div p} def fix_span_elements(node) - if node.name == 'span' && node.at('div') + if (INLINE_ELEMENTS.include?(node.name) && BLOCK_ELEMENTS.any? { |e| node.at(e) }) node.swap(node.children) end diff --git a/spec/components/html_to_markdown_spec.rb b/spec/components/html_to_markdown_spec.rb index 1aef7411208..1070cf07b51 100644 --- a/spec/components/html_to_markdown_spec.rb +++ b/spec/components/html_to_markdown_spec.rb @@ -236,9 +236,14 @@ describe HtmlToMarkdown do expect(html_to_markdown("")).to eq("") end - it "handles divs within spans" do - html = "
1st paragraph
2nd paragraph
" - expect(html_to_markdown(html)).to eq("1st paragraph\n2nd paragraph") + it "handles

and

within " do + html = "
1st paragraph
2nd paragraph

3rd paragraph

" + expect(html_to_markdown(html)).to eq("1st paragraph\n2nd paragraph\n\n3rd paragraph") + end + + it "handles

and

within " do + html = "1st paragraph
2nd paragraph
3rd paragraph

4th paragraph

" + expect(html_to_markdown(html)).to eq("1st paragraph\n2nd paragraph\n3rd paragraph\n\n4th paragraph") end context "with an oddly placed
" do