mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: skip hidden nodes when converting from HTML to Markdown
This commit is contained in:
parent
09cb61b533
commit
c8044c6956
@ -37,6 +37,8 @@ class HtmlToMarkdown
|
|||||||
end
|
end
|
||||||
|
|
||||||
def visit(node)
|
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
|
if node.description&.block? && node.parent&.description&.block? && @stack[-1].markdown.size > 0
|
||||||
block = @stack[-1].dup
|
block = @stack[-1].dup
|
||||||
@markdown << format_block
|
@markdown << format_block
|
||||||
|
@ -21,6 +21,10 @@ describe HtmlToMarkdown do
|
|||||||
)).to eq("Hello,\n\nThis is the 1st paragraph.\n\nThis is another paragraph")
|
)).to eq("Hello,\n\nThis is the 1st paragraph.\n\nThis is another paragraph")
|
||||||
end
|
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
|
it "converts <strong>" do
|
||||||
expect(html_to_markdown("<strong>Strong</strong>")).to eq("**Strong**")
|
expect(html_to_markdown("<strong>Strong</strong>")).to eq("**Strong**")
|
||||||
expect(html_to_markdown("<strong>Str*ng</strong>")).to eq("__Str*ng__")
|
expect(html_to_markdown("<strong>Str*ng</strong>")).to eq("__Str*ng__")
|
||||||
|
Loading…
Reference in New Issue
Block a user