From c8044c695686a34f0daf34ceed052169d888fa1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 3 May 2017 19:34:03 +0200 Subject: [PATCH] FIX: skip hidden nodes when converting from HTML to Markdown --- lib/html_to_markdown.rb | 2 ++ spec/components/html_to_markdown_spec.rb | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/html_to_markdown.rb b/lib/html_to_markdown.rb index 6e72d65fd4e..40997fa5c94 100644 --- a/lib/html_to_markdown.rb +++ b/lib/html_to_markdown.rb @@ -37,6 +37,8 @@ class HtmlToMarkdown end def visit(node) + return if node["style"] && node["style"][/display[[:space:]]*:[[:space:]]*none/] + if node.description&.block? && node.parent&.description&.block? && @stack[-1].markdown.size > 0 block = @stack[-1].dup @markdown << format_block diff --git a/spec/components/html_to_markdown_spec.rb b/spec/components/html_to_markdown_spec.rb index 1e622e93f18..52c0eb670a1 100644 --- a/spec/components/html_to_markdown_spec.rb +++ b/spec/components/html_to_markdown_spec.rb @@ -21,6 +21,10 @@ describe HtmlToMarkdown do )).to eq("Hello,\n\nThis is the 1st paragraph.\n\nThis is another paragraph") end + it "skips hidden tags" do + expect(html_to_markdown(%Q{

Hello cruel World!

})).to eq("Hello World!") + end + it "converts " do expect(html_to_markdown("Strong")).to eq("**Strong**") expect(html_to_markdown("Str*ng")).to eq("__Str*ng__")