2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-13 01:33:13 +08:00
|
|
|
require 'email_cook'
|
2017-11-15 23:39:29 +08:00
|
|
|
require 'pretty_text'
|
2016-07-13 01:33:13 +08:00
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe EmailCook do
|
2017-11-15 23:39:29 +08:00
|
|
|
it "uses to PrettyText when there is no [plaintext] in raw" do
|
|
|
|
raw = "**Hello world!**"
|
|
|
|
expect(cook(raw)).to eq(PrettyText.cook(raw))
|
|
|
|
end
|
2016-07-13 01:33:13 +08:00
|
|
|
|
2017-11-15 23:39:29 +08:00
|
|
|
it "adds linebreaks to short lines" do
|
|
|
|
raw = plaintext("hello\nworld\n")
|
|
|
|
expect(cook(raw)).to eq("hello\n<br>world\n<br>")
|
2016-07-13 01:33:13 +08:00
|
|
|
end
|
|
|
|
|
2016-07-13 01:49:03 +08:00
|
|
|
it "doesn't add linebreaks to long lines" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long = plaintext(<<~EMAIL)
|
2017-11-15 23:39:29 +08:00
|
|
|
Hello,
|
|
|
|
|
|
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc convallis volutpat
|
|
|
|
risus. Nulla ac faucibus quam, quis cursus lorem. Sed rutrum eget nunc sed accumsan.
|
|
|
|
Vestibulum feugiat mi vitae turpis tempor dignissim.
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
EMAIL
|
2017-11-15 23:39:29 +08:00
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long_cooked = (+<<~HTML).strip!
|
2017-11-15 23:39:29 +08:00
|
|
|
Hello,
|
|
|
|
<br>
|
|
|
|
<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc convallis volutpat
|
|
|
|
risus. Nulla ac faucibus quam, quis cursus lorem. Sed rutrum eget nunc sed accumsan.
|
|
|
|
Vestibulum feugiat mi vitae turpis tempor dignissim.
|
|
|
|
<br>
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
HTML
|
2017-11-15 23:39:29 +08:00
|
|
|
|
|
|
|
expect(cook(long)).to eq(long_cooked)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "replaces a blank line with 2 linebreaks" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long = plaintext(<<~EMAIL)
|
2017-11-15 23:39:29 +08:00
|
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc convallis volutpat
|
|
|
|
risus.
|
|
|
|
Nulla ac faucibus quam, quis cursus lorem. Sed rutrum eget nunc sed accumsan.
|
|
|
|
|
|
|
|
Vestibulum feugiat mi vitae turpis tempor dignissim.
|
|
|
|
|
|
|
|
Stet clita kasd gubergren.
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
EMAIL
|
2017-11-15 23:39:29 +08:00
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long_cooked = (+<<~HTML).strip!
|
2017-11-15 23:39:29 +08:00
|
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc convallis volutpat
|
|
|
|
risus.
|
|
|
|
<br>Nulla ac faucibus quam, quis cursus lorem. Sed rutrum eget nunc sed accumsan.
|
|
|
|
<br>
|
|
|
|
<br>Vestibulum feugiat mi vitae turpis tempor dignissim.
|
|
|
|
<br>
|
|
|
|
<br>Stet clita kasd gubergren.
|
|
|
|
<br>
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
HTML
|
2017-11-15 23:39:29 +08:00
|
|
|
|
|
|
|
expect(cook(long)).to eq(long_cooked)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "escapes HTML" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long = plaintext(<<~EMAIL)
|
2017-11-15 23:39:29 +08:00
|
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
|
|
|
|
|
|
<form name="f1" method="post" action="test.html" onsubmit="javascript:showAlert()">
|
|
|
|
<input type="submit" name="submit" value="Click this button" />
|
|
|
|
</form>
|
|
|
|
|
|
|
|
Nunc convallis volutpat risus.
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
EMAIL
|
2016-07-13 01:49:03 +08:00
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long_cooked = (+<<~HTML).strip!
|
2017-11-15 23:39:29 +08:00
|
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
|
|
<br>
|
|
|
|
<br><form name="f1" method="post" action="test.html" onsubmit="javascript:showAlert()">
|
|
|
|
<input type="submit" name="submit" value="Click this button" />
|
|
|
|
</form>
|
|
|
|
<br>
|
|
|
|
<br>Nunc convallis volutpat risus.
|
|
|
|
<br>
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
HTML
|
2016-07-13 01:49:03 +08:00
|
|
|
|
2017-11-15 23:39:29 +08:00
|
|
|
expect(cook(long)).to eq(long_cooked)
|
2016-07-13 01:49:03 +08:00
|
|
|
end
|
|
|
|
|
2017-11-18 23:50:27 +08:00
|
|
|
it "replaces indentation of more than 2 spaces with corresponding amount of non-breaking spaces" do
|
|
|
|
nbsp = "\u00A0"
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long = plaintext(<<~EMAIL)
|
2017-11-18 23:50:27 +08:00
|
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
|
|
|
2021-05-21 09:43:47 +08:00
|
|
|
this is intended by 4 spaces
|
|
|
|
this is intended by 1 space
|
2017-11-18 23:50:27 +08:00
|
|
|
no indentation, but lots of spaces
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
EMAIL
|
2017-11-18 23:50:27 +08:00
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long_cooked = (+<<~HTML).strip!
|
2017-11-18 23:50:27 +08:00
|
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
|
|
<br>
|
2021-05-21 09:43:47 +08:00
|
|
|
<br>#{nbsp}#{nbsp}#{nbsp}#{nbsp}this is intended by 4 spaces
|
|
|
|
<br> this is intended by 1 space
|
2017-11-18 23:50:27 +08:00
|
|
|
<br>no indentation, but lots of spaces
|
|
|
|
<br>
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
HTML
|
2017-11-18 23:50:27 +08:00
|
|
|
|
|
|
|
expect(cook(long)).to eq(long_cooked)
|
|
|
|
end
|
|
|
|
|
2017-11-15 23:39:29 +08:00
|
|
|
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>')
|
2016-07-13 01:33:13 +08:00
|
|
|
end
|
2016-07-19 01:46:13 +08:00
|
|
|
|
2017-11-15 23:39:29 +08:00
|
|
|
it "autolinks without the beginning of a line" do
|
|
|
|
raw = plaintext("my site: https://www.eviltrout.com")
|
|
|
|
expect(cook(raw)).to eq('my site: <a href="https://www.eviltrout.com">https://www.eviltrout.com</a><br>')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "autolinks without the end of a line" do
|
|
|
|
raw = plaintext("https://www.eviltrout.com is my site")
|
|
|
|
expect(cook(raw)).to eq('<a href="https://www.eviltrout.com">https://www.eviltrout.com</a> is my site<br>')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "links even within a quote" do
|
|
|
|
raw = plaintext("> https://www.eviltrout.com is my site")
|
|
|
|
expect(cook(raw)).to eq('<blockquote><a href="https://www.eviltrout.com">https://www.eviltrout.com</a> is my site<br></blockquote>')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "it works and does not interpret Markdown in plaintext and elided" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long = <<~EMAIL
|
2017-11-15 23:39:29 +08:00
|
|
|
[plaintext]
|
|
|
|
*Lorem ipsum* dolor sit amet, consectetur adipiscing elit.
|
|
|
|
[/plaintext]
|
|
|
|
[attachments]
|
|
|
|
<img src='some_image.png' width='100' height='100'>
|
|
|
|
[/attachments]
|
|
|
|
[elided]
|
|
|
|
At vero eos *et accusam* et justo duo dolores et ea rebum.
|
|
|
|
[/elided]
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
EMAIL
|
2017-11-15 23:39:29 +08:00
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long_cooked = <<~HTML
|
2017-11-15 23:39:29 +08:00
|
|
|
*Lorem ipsum* dolor sit amet, consectetur adipiscing elit.<br>
|
|
|
|
<br><img src='some_image.png' width='100' height='100'>
|
|
|
|
<br><br>
|
|
|
|
|
|
|
|
<details class='elided'>
|
|
|
|
<summary title='Show trimmed content'>···</summary>
|
2017-12-06 08:47:31 +08:00
|
|
|
|
2017-11-15 23:39:29 +08:00
|
|
|
At vero eos *et accusam* et justo duo dolores et ea rebum.<br>
|
2017-12-06 08:47:31 +08:00
|
|
|
|
2017-11-15 23:39:29 +08:00
|
|
|
</details>
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
HTML
|
2017-11-15 23:39:29 +08:00
|
|
|
|
|
|
|
expect(cook(long)).to eq(long_cooked)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works without attachments" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long = <<~EMAIL
|
2017-11-15 23:39:29 +08:00
|
|
|
[plaintext]
|
|
|
|
*Lorem ipsum* dolor sit amet, consectetur adipiscing elit.
|
|
|
|
[/plaintext]
|
|
|
|
[elided]
|
|
|
|
At vero eos *et accusam* et justo duo dolores et ea rebum.
|
|
|
|
[/elided]
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
EMAIL
|
2017-11-15 23:39:29 +08:00
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
long_cooked = <<~HTML
|
2017-11-15 23:39:29 +08:00
|
|
|
*Lorem ipsum* dolor sit amet, consectetur adipiscing elit.<br>
|
|
|
|
<br><br>
|
|
|
|
|
|
|
|
<details class='elided'>
|
|
|
|
<summary title='Show trimmed content'>···</summary>
|
2017-12-06 08:47:31 +08:00
|
|
|
|
2017-11-15 23:39:29 +08:00
|
|
|
At vero eos *et accusam* et justo duo dolores et ea rebum.<br>
|
2017-12-06 08:47:31 +08:00
|
|
|
|
2017-11-15 23:39:29 +08:00
|
|
|
</details>
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
HTML
|
2017-11-15 23:39:29 +08:00
|
|
|
|
|
|
|
expect(cook(long)).to eq(long_cooked)
|
2017-10-18 02:36:57 +08:00
|
|
|
end
|
|
|
|
|
2017-11-15 23:39:29 +08:00
|
|
|
def cook(raw)
|
|
|
|
EmailCook.new(raw).cook
|
2016-07-19 01:46:13 +08:00
|
|
|
end
|
2016-07-19 02:38:40 +08:00
|
|
|
|
2017-11-15 23:39:29 +08:00
|
|
|
def plaintext(text)
|
|
|
|
"[plaintext]\n#{text}\n[/plaintext]"
|
2016-07-19 02:38:40 +08:00
|
|
|
end
|
2016-07-13 01:33:13 +08:00
|
|
|
end
|