mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 07:52:19 +08:00
FIX: generate valid markdown from <br></b> in an email (#5022)
* FIX: generate valid markdown from <br></b> in an email * FIX: don't generate markdown for empty <strong> or <em> tags in emails
This commit is contained in:
parent
902be91a5a
commit
65d5cd7239
|
@ -186,18 +186,22 @@ class HtmlToMarkdown
|
|||
end
|
||||
|
||||
def visit_strong(node)
|
||||
return if node.text.blank?
|
||||
delimiter = node.text["*"] ? "__" : "**"
|
||||
@stack[-1].markdown << delimiter
|
||||
traverse(node)
|
||||
@stack[-1].markdown.chomp!
|
||||
@stack[-1].markdown << delimiter
|
||||
end
|
||||
|
||||
alias :visit_b :visit_strong
|
||||
|
||||
def visit_em(node)
|
||||
return if node.text.blank?
|
||||
delimiter = node.text["*"] ? "_" : "*"
|
||||
@stack[-1].markdown << delimiter
|
||||
traverse(node)
|
||||
@stack[-1].markdown.chomp!
|
||||
@stack[-1].markdown << delimiter
|
||||
end
|
||||
|
||||
|
|
|
@ -228,4 +228,32 @@ describe HtmlToMarkdown do
|
|||
expect(html_to_markdown(html)).to eq("1st paragraph\n2nd paragraph")
|
||||
end
|
||||
|
||||
context "with an oddly placed <br>" do
|
||||
|
||||
it "handles <strong>" do
|
||||
expect(html_to_markdown("<strong>Bold<br></strong>")).to eq("**Bold**")
|
||||
expect(html_to_markdown("<strong>Bold<br>text</strong>")).to eq("**Bold\ntext**")
|
||||
end
|
||||
|
||||
it "handles <em>" do
|
||||
expect(html_to_markdown("<em>Italic<br></em>")).to eq("*Italic*")
|
||||
expect(html_to_markdown("<em>Italic<br>text</em>")).to eq("*Italic\ntext*")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "with an empty tag" do
|
||||
|
||||
it "handles <strong>" do
|
||||
expect(html_to_markdown("<strong></strong>")).to eq("")
|
||||
expect(html_to_markdown("<strong> </strong>")).to eq("")
|
||||
end
|
||||
|
||||
it "handles <em>" do
|
||||
expect(html_to_markdown("<em></em>")).to eq("")
|
||||
expect(html_to_markdown("<em> </em>")).to eq("")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user