",
"allows autolinking within a list without inserting a paragraph.");
cooked("[3]: http://eviltrout.com", "", "It doesn't autolink markdown link references");
cooked("[]: http://eviltrout.com", "
", "It doesn't accept empty link references");
cooked("[b]label[/b]: description", "
label: description
", "It doesn't accept BBCode as link references");
cooked("http://discourse.org and http://discourse.org/another_url and http://www.imdb.com/name/nm2225369",
"
",
"it translates category hashtag into links");
cooked("Check out #category-hashtag",
"
Check out #category-hashtag
",
"it does not translate category hashtag into links if it is not a valid category hashtag");
cookedOptions("[#category-hashtag](http://www.test.com)", alwaysTrue,
"
", "allows escaping em");
});
test("New Lines", function() {
// Note: This behavior was discussed and we determined it does not make sense to do this
// unless you're using traditional line breaks
cooked("_abc\ndef_", "
_abc def_
", "it does not allow markup to span new lines");
cooked("_abc\n\ndef_", "
_abc
\n\n
def_
", "it does not allow markup to span new paragraphs");
});
test("Oneboxing", function() {
function matches(input, regexp) {
return new PrettyText(defaultOpts).cook(input).match(regexp);
};
ok(!matches("- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org", /onebox/),
"doesn't onebox a link within a list");
ok(matches("http://test.com", /onebox/), "adds a onebox class to a link on its own line");
ok(matches("http://test.com\nhttp://test2.com", /onebox[\s\S]+onebox/m), "supports multiple links");
ok(!matches("http://test.com bob", /onebox/), "doesn't onebox links that have trailing text");
ok(!matches("[Tom Cruise](http://www.tomcruise.com/)", "onebox"), "Markdown links with labels are not oneboxed");
ok(matches("[http://www.tomcruise.com/](http://www.tomcruise.com/)",
"onebox"),
"Markdown links where the label is the same as the url are oneboxed");
cooked("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street",
"
",
"works with links that have underscores in them");
});
test("links with full urls", function() {
cooked("[http://eviltrout.com][1] is a url\n\n[1]: http://eviltrout.com",
"
",
"it works when nesting standard markdown code blocks within a fenced code block");
cooked("`$&`",
"
$&
",
"it works even when hoisting special replacement patterns");
});
test('basic bbcode', function() {
cookedPara("[b]strong[/b]", "strong", "bolds text");
cookedPara("[i]emphasis[/i]", "emphasis", "italics text");
cookedPara("[u]underlined[/u]", "underlined", "underlines text");
cookedPara("[s]strikethrough[/s]", "strikethrough", "strikes-through text");
cookedPara("[img]http://eviltrout.com/eviltrout.png[/img]", "", "links images");
cookedPara("[email]eviltrout@mailinator.com[/email]", "eviltrout@mailinator.com", "supports [email] without a title");
cookedPara("[b]evil [i]trout[/i][/b]",
"evil trout",
"allows embedding of tags");
cookedPara("[EMAIL]eviltrout@mailinator.com[/EMAIL]", "eviltrout@mailinator.com", "supports upper case bbcode");
cookedPara("[b]strong [b]stronger[/b][/b]", "strong stronger", "accepts nested bbcode tags");
});
test('urls', function() {
cookedPara("[url]not a url[/url]", "not a url", "supports [url] that isn't a url");
cookedPara("[url]abc.com[/url]", "abc.com", "no error when a url has no protocol and begins with a");
cookedPara("[url]http://bettercallsaul.com[/url]", "http://bettercallsaul.com", "supports [url] without parameter");
cookedPara("[url=http://example.com]example[/url]", "example", "supports [url] with given href");
cookedPara("[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]",
"",
"supports [url] with an embedded [img]");
});
test('invalid bbcode', function() {
const result = new PrettyText({ lookupAvatar: false }).cook("[code]I am not closed\n\nThis text exists.");
equal(result, "
[code]I am not closed
\n\n
This text exists.
", "does not raise an error with an open bbcode tag.");
});
test('code', function() {
cookedPara("[code]\nx++\n[/code]", "
x++
", "makes code into pre");
cookedPara("[code]\nx++\ny++\nz++\n[/code]", "
x++\ny++\nz++
", "makes code into pre");
cookedPara("[code]abc\n#def\n[/code]", '
abc\n#def
', 'it handles headings in a [code] block');
cookedPara("[code]\n s[/code]",
"
s
",
"it doesn't trim leading whitespace");
});
test('lists', function() {
cookedPara("[ul][li]option one[/li][/ul]", "
option one
", "creates an ul");
cookedPara("[ol][li]option one[/li][/ol]", "
option one
", "creates an ol");
cookedPara("[ul]\n[li]option one[/li]\n[li]option two[/li]\n[/ul]", "
option one
option two
", "suppresses empty lines in lists");
});
test('tags with arguments', function() {
cookedPara("[url=http://bettercallsaul.com]better call![/url]", "better call!", "supports [url] with a title");
cookedPara("[email=eviltrout@mailinator.com]evil trout[/email]", "evil trout", "supports [email] with a title");
cookedPara("[u][i]abc[/i][/u]", "abc", "can nest tags");
cookedPara("[b]first[/b] [b]second[/b]", "firstsecond", "can bold two things on the same line");
});
test("quotes", function() {
const post = Post.create({
cooked: "
lorem ipsum
",
username: "eviltrout",
post_number: 1,
topic_id: 2
});
function formatQuote(val, expected, text) {
equal(Quote.build(post, val), expected, text);
};
formatQuote(undefined, "", "empty string for undefined content");
formatQuote(null, "", "empty string for null content");
formatQuote("", "", "empty string for empty string content");
formatQuote("lorem", "[quote=\"eviltrout, post:1, topic:2\"]\nlorem\n[/quote]\n\n", "correctly formats quotes");
formatQuote(" lorem \t ",
"[quote=\"eviltrout, post:1, topic:2\"]\nlorem\n[/quote]\n\n",
"trims white spaces before & after the quoted contents");
formatQuote("lorem ipsum",
"[quote=\"eviltrout, post:1, topic:2, full:true\"]\nlorem ipsum\n[/quote]\n\n",
"marks quotes as full when the quote is the full message");
formatQuote("**lorem** ipsum",
"[quote=\"eviltrout, post:1, topic:2, full:true\"]\n**lorem** ipsum\n[/quote]\n\n",
"keeps BBCode formatting");
formatQuote("this is a bug",
"[quote=\"eviltrout, post:1, topic:2\"]\nthis is <not> a bug\n[/quote]\n\n",
"it escapes the contents of the quote");
cookedPara("[quote]test[/quote]",
"",
"it supports quotes without params");
cookedPara("[quote]\n*test*\n[/quote]",
"",
"it doesn't insert a new line for italics");
cookedPara("[quote=,script='a'>