FIX: skip hidden nodes when converting from HTML to Markdown

This commit is contained in:
Régis Hanol 2017-05-03 19:34:03 +02:00
parent 09cb61b533
commit c8044c6956
2 changed files with 6 additions and 0 deletions

View File

@ -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

View File

@ -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{<p>Hello <span style="display: none">cruel </span>World!</p>})).to eq("Hello World!")
end
it "converts <strong>" do
expect(html_to_markdown("<strong>Strong</strong>")).to eq("**Strong**")
expect(html_to_markdown("<strong>Str*ng</strong>")).to eq("__Str*ng__")