replace indentation with non-breaking spaces when cooking emails

This commit is contained in:
Gerhard Schlager 2017-11-18 16:50:27 +01:00
parent 32dd1e66be
commit 546b206da0
2 changed files with 24 additions and 0 deletions

View File

@ -47,6 +47,8 @@ class EmailCook
quote_buffer = ""
text.each_line do |line|
# replace indentation with non-breaking spaces
line.sub!(/^\s{2,}/) { |s| "\u00A0" * s.length }
if line =~ /^\s*>/
in_quote = true

View File

@ -84,6 +84,28 @@ describe EmailCook do
expect(cook(long)).to eq(long_cooked)
end
it "replaces indentation of more than 2 spaces with corresponding amount of non-breaking spaces" do
nbsp = "\u00A0"
long = plaintext(<<~LONG_EMAIL)
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
this is indended by 4 spaces
this is indended by 1 space
no indentation, but lots of spaces
LONG_EMAIL
long_cooked = <<~LONG_COOKED.strip!
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<br>
<br>#{nbsp}#{nbsp}#{nbsp}#{nbsp}this is indended by 4 spaces
<br> this is indended by 1 space
<br>no indentation, but lots of spaces
<br>
LONG_COOKED
expect(cook(long)).to eq(long_cooked)
end
it "creates oneboxed link when the line contains only a link" do
raw = plaintext("https://www.eviltrout.com")
expect(cook(raw)).to eq('<a href="https://www.eviltrout.com" class="onebox" target="_blank">https://www.eviltrout.com</a><br>')