FIX: Weird mixture of line breaks resulted in wrong email trimming

This commit is contained in:
Gerhard Schlager 2018-12-17 18:38:11 +01:00
parent 98d09c90ac
commit 37461a6398
2 changed files with 11 additions and 1 deletions

View File

@ -32,6 +32,7 @@ class HtmlToMarkdown
node.content = node.content.gsub(/\A[[:space:]]+/, "") if node.previous_element.nil? && node.parent.description&.block?
node.content = node.content.gsub(/[[:space:]]+\z/, "") if node.next_element&.description&.block?
node.content = node.content.gsub(/[[:space:]]+\z/, "") if node.next_element.nil? && node.parent.description&.block?
node.content = node.content.gsub(/\r\n?/, "\n")
node.remove if node.content.empty?
end
end
@ -200,7 +201,7 @@ class HtmlToMarkdown
@stack[-1].markdown << " " if node.text[0] == " "
@stack[-1].markdown << delimiter
traverse(node)
@stack[-1].markdown.chomp!
@stack[-1].markdown.gsub!(/\n+$/, "")
if @stack[-1].markdown[-1] == " "
@stack[-1].markdown.chomp!(" ")
append_space = true

View File

@ -33,6 +33,15 @@ describe HtmlToMarkdown do
it "converts <b>" do
expect(html_to_markdown("<b>Bold</b>")).to eq("**Bold**")
expect(html_to_markdown("<b>B*ld</b>")).to eq("__B*ld__")
html = <<~HTML
<p><b>Bold
<br>
<br>
</b>
</p>
HTML
expect(html_to_markdown(html)).to eq("**Bold**")
end
it "converts <em>" do