2020-04-08 22:28:23 +08:00
|
|
|
|
import { buildQuote } from "discourse/lib/quote";
|
2016-06-15 02:31:51 +08:00
|
|
|
|
import Post from "discourse/models/post";
|
2020-01-17 01:56:53 +08:00
|
|
|
|
import PrettyText, { buildOptions } from "pretty-text/pretty-text";
|
2019-03-15 12:44:49 +08:00
|
|
|
|
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
|
2019-06-11 09:13:39 +08:00
|
|
|
|
import {
|
|
|
|
|
applyCachedInlineOnebox,
|
|
|
|
|
deleteCachedInlineOnebox
|
|
|
|
|
} from "pretty-text/inline-oneboxer";
|
2019-12-09 22:20:03 +08:00
|
|
|
|
import { extractDataAttribute } from "pretty-text/engines/discourse-markdown-it";
|
2020-03-31 02:16:10 +08:00
|
|
|
|
import { registerEmoji } from "pretty-text/emoji";
|
2016-06-15 02:31:51 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.module("lib:pretty-text");
|
2016-06-15 02:31:51 +08:00
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
const rawOpts = {
|
2016-06-15 02:31:51 +08:00
|
|
|
|
siteSettings: {
|
|
|
|
|
enable_emoji: true,
|
2018-01-24 10:23:27 +08:00
|
|
|
|
enable_emoji_shortcuts: true,
|
2017-12-08 00:30:47 +08:00
|
|
|
|
enable_mentions: true,
|
2016-06-15 02:31:51 +08:00
|
|
|
|
emoji_set: "emoji_one",
|
|
|
|
|
highlighted_languages: "json|ruby|javascript",
|
|
|
|
|
default_code_lang: "auto",
|
2018-02-01 13:16:14 +08:00
|
|
|
|
enable_markdown_linkify: true,
|
|
|
|
|
markdown_linkify_tlds: "com"
|
2016-06-15 02:31:51 +08:00
|
|
|
|
},
|
|
|
|
|
getURL: url => url
|
2017-07-14 20:27:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const defaultOpts = buildOptions(rawOpts);
|
2016-06-15 02:31:51 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.assert.cooked = function(input, expected, message) {
|
|
|
|
|
const actual = new PrettyText(defaultOpts).cook(input);
|
|
|
|
|
this.pushResult({
|
|
|
|
|
result: actual === expected.replace(/\/>/g, ">"),
|
|
|
|
|
actual,
|
|
|
|
|
expected,
|
|
|
|
|
message
|
|
|
|
|
});
|
2016-06-15 02:31:51 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.assert.cookedOptions = function(input, opts, expected, message) {
|
2017-07-14 20:27:28 +08:00
|
|
|
|
const merged = _.merge({}, rawOpts, opts);
|
|
|
|
|
const actual = new PrettyText(buildOptions(merged)).cook(input);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
this.pushResult({
|
|
|
|
|
result: actual === expected,
|
|
|
|
|
actual,
|
|
|
|
|
expected,
|
|
|
|
|
message
|
|
|
|
|
});
|
2013-06-19 06:03:36 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.assert.cookedPara = function(input, expected, message) {
|
|
|
|
|
QUnit.assert.cooked(input, `<p>${expected}</p>`, message);
|
2013-06-22 02:06:20 +08:00
|
|
|
|
};
|
2013-06-19 06:03:36 +08:00
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
QUnit.skip("Pending Engine fixes and spec fixes", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"Derpy: http://derp.com?_test_=1",
|
|
|
|
|
'<p>Derpy: <a href=https://derp.com?_test_=1"http://derp.com?_test_=1">http://derp.com?_test_=1</a></p>',
|
|
|
|
|
"works with underscores in urls"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"**a*_b**",
|
|
|
|
|
"<p><strong>a*_b</strong></p>",
|
|
|
|
|
"allows for characters within bold"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QUnit.test("buildOptions", assert => {
|
|
|
|
|
assert.ok(
|
|
|
|
|
buildOptions({ siteSettings: { enable_emoji: true } }).discourse.features
|
|
|
|
|
.emoji,
|
|
|
|
|
"emoji enabled"
|
|
|
|
|
);
|
|
|
|
|
assert.ok(
|
|
|
|
|
!buildOptions({ siteSettings: { enable_emoji: false } }).discourse.features
|
|
|
|
|
.emoji,
|
|
|
|
|
"emoji disabled"
|
|
|
|
|
);
|
2016-06-15 02:31:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("basic cooking", assert => {
|
|
|
|
|
assert.cooked("hello", "<p>hello</p>", "surrounds text with paragraphs");
|
|
|
|
|
assert.cooked("**evil**", "<p><strong>evil</strong></p>", "it bolds text.");
|
|
|
|
|
assert.cooked("__bold__", "<p><strong>bold</strong></p>", "it bolds text.");
|
|
|
|
|
assert.cooked("*trout*", "<p><em>trout</em></p>", "it italicizes text.");
|
|
|
|
|
assert.cooked("_trout_", "<p><em>trout</em></p>", "it italicizes text.");
|
2018-03-08 09:19:32 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"***hello***",
|
|
|
|
|
"<p><em><strong>hello</strong></em></p>",
|
|
|
|
|
"it can do bold and italics at once."
|
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"word_with_underscores",
|
|
|
|
|
"<p>word_with_underscores</p>",
|
|
|
|
|
"it doesn't do intraword italics"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"common/_special_font_face.html.erb",
|
|
|
|
|
"<p>common/_special_font_face.html.erb</p>",
|
|
|
|
|
"it doesn't intraword with a slash"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"hello \\*evil\\*",
|
|
|
|
|
"<p>hello *evil*</p>",
|
|
|
|
|
"it supports escaping of asterisks"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"hello \\_evil\\_",
|
|
|
|
|
"<p>hello _evil_</p>",
|
|
|
|
|
"it supports escaping of italics"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"brussels sprouts are *awful*.",
|
|
|
|
|
"<p>brussels sprouts are <em>awful</em>.</p>",
|
|
|
|
|
"it doesn't swallow periods."
|
|
|
|
|
);
|
2013-06-21 23:36:33 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Nested bold and italics", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"*this is italic **with some bold** inside*",
|
|
|
|
|
"<p><em>this is italic <strong>with some bold</strong> inside</em></p>",
|
|
|
|
|
"it handles nested bold in italics"
|
|
|
|
|
);
|
2014-09-23 04:51:48 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Traditional Line Breaks", assert => {
|
2016-06-15 02:31:51 +08:00
|
|
|
|
const input = "1\n2\n3";
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
input,
|
|
|
|
|
"<p>1<br>\n2<br>\n3</p>",
|
|
|
|
|
"automatically handles trivial newlines"
|
|
|
|
|
);
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
input,
|
|
|
|
|
{ siteSettings: { traditional_markdown_linebreaks: true } },
|
|
|
|
|
"<p>1\n2\n3</p>"
|
|
|
|
|
);
|
2013-08-27 03:21:23 +08:00
|
|
|
|
});
|
2013-06-21 23:36:33 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Unbalanced underscores", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"[evil_trout][1] hello_\n\n[1]: http://eviltrout.com",
|
|
|
|
|
'<p><a href="http://eviltrout.com">evil_trout</a> hello_</p>'
|
|
|
|
|
);
|
2013-11-21 00:53:06 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Line Breaks", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"[] first choice\n[] second choice",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"<p>[] first choice<br>\n[] second choice</p>",
|
2013-08-27 03:21:23 +08:00
|
|
|
|
"it handles new lines correctly with [] options"
|
|
|
|
|
);
|
2013-10-19 03:20:27 +08:00
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
// note this is a change from previous engine but is correct
|
|
|
|
|
// we have an html block and behavior is defined per common mark
|
|
|
|
|
// spec
|
|
|
|
|
// ole engine would wrap trout in a <p>
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"<blockquote>evil</blockquote>\ntrout",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"<blockquote>evil</blockquote>\ntrout",
|
2013-10-19 03:20:27 +08:00
|
|
|
|
"it doesn't insert <br> after blockquotes"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"leading<blockquote>evil</blockquote>\ntrout",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"<p>leading<blockquote>evil</blockquote><br>\ntrout</p>",
|
2013-10-19 03:20:27 +08:00
|
|
|
|
"it doesn't insert <br> after blockquotes with leading text"
|
|
|
|
|
);
|
2013-06-19 06:03:36 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Paragraphs for HTML", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"<div>hello world</div>",
|
|
|
|
|
"<div>hello world</div>",
|
|
|
|
|
"it doesn't surround <div> with paragraphs"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"<p>hello world</p>",
|
|
|
|
|
"<p>hello world</p>",
|
|
|
|
|
"it doesn't surround <p> with paragraphs"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"<i>hello world</i>",
|
|
|
|
|
"<p><i>hello world</i></p>",
|
|
|
|
|
"it surrounds inline <i> html tags with paragraphs"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"<b>hello world</b>",
|
|
|
|
|
"<p><b>hello world</b></p>",
|
|
|
|
|
"it surrounds inline <b> html tags with paragraphs"
|
|
|
|
|
);
|
2013-10-19 03:20:27 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Links", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"EvilTrout: http://eviltrout.com",
|
2013-08-23 06:03:01 +08:00
|
|
|
|
'<p>EvilTrout: <a href="http://eviltrout.com">http://eviltrout.com</a></p>',
|
|
|
|
|
"autolinks a URL"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2019-06-11 09:13:39 +08:00
|
|
|
|
const link = "http://www.youtube.com/watch?v=1MrpeBRkM5A";
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
2019-06-11 09:13:39 +08:00
|
|
|
|
`Youtube: ${link}`,
|
2020-05-08 04:08:48 +08:00
|
|
|
|
`<p>Youtube: <a href="${link}" class="inline-onebox-loading">${link}</a></p>`,
|
2013-06-19 06:03:36 +08:00
|
|
|
|
"allows links to contain query params"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2019-06-11 09:13:39 +08:00
|
|
|
|
try {
|
|
|
|
|
applyCachedInlineOnebox(link, {});
|
|
|
|
|
|
|
|
|
|
assert.cooked(
|
|
|
|
|
`Youtube: ${link}`,
|
|
|
|
|
`<p>Youtube: <a href="${link}">${link}</a></p>`
|
|
|
|
|
);
|
|
|
|
|
} finally {
|
|
|
|
|
deleteCachedInlineOnebox(link);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"Derpy: http://derp.com?__test=1",
|
2020-05-08 04:08:48 +08:00
|
|
|
|
`<p>Derpy: <a href="http://derp.com?__test=1" class="inline-onebox-loading">http://derp.com?__test=1</a></p>`,
|
2013-08-09 06:14:12 +08:00
|
|
|
|
"works with double underscores in urls"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"Atwood: www.codinghorror.com",
|
2013-06-19 06:03:36 +08:00
|
|
|
|
'<p>Atwood: <a href="http://www.codinghorror.com">www.codinghorror.com</a></p>',
|
|
|
|
|
"autolinks something that begins with www"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"Atwood: http://www.codinghorror.com",
|
2013-06-19 06:03:36 +08:00
|
|
|
|
'<p>Atwood: <a href="http://www.codinghorror.com">http://www.codinghorror.com</a></p>',
|
|
|
|
|
"autolinks a URL with http://www"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"EvilTrout: http://eviltrout.com hello",
|
2013-08-22 10:49:55 +08:00
|
|
|
|
'<p>EvilTrout: <a href="http://eviltrout.com">http://eviltrout.com</a> hello</p>',
|
|
|
|
|
"autolinks with trailing text"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"here is [an example](http://twitter.com)",
|
2013-06-19 06:03:36 +08:00
|
|
|
|
'<p>here is <a href="http://twitter.com">an example</a></p>',
|
|
|
|
|
"supports markdown style links"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)",
|
2020-05-08 04:08:48 +08:00
|
|
|
|
`<p>Batman: <a href="http://en.wikipedia.org/wiki/The_Dark_Knight_(film)" class="inline-onebox-loading">http://en.wikipedia.org/wiki/The_Dark_Knight_(film)</a></p>`,
|
2013-06-19 06:03:36 +08:00
|
|
|
|
"autolinks a URL with parentheses (like Wikipedia)"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"Here's a tweet:\nhttps://twitter.com/evil_trout/status/345954894420787200",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<p>Here\'s a tweet:<br>\n<a href="https://twitter.com/evil_trout/status/345954894420787200" class="onebox" target="_blank">https://twitter.com/evil_trout/status/345954894420787200</a></p>',
|
2013-08-09 06:14:12 +08:00
|
|
|
|
"It doesn't strip the new line."
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"1. View @eviltrout's profile here: http://meta.discourse.org/u/eviltrout/activity<br/>next line.",
|
2020-05-08 04:08:48 +08:00
|
|
|
|
`<ol>\n<li>View <span class="mention">@eviltrout</span>\'s profile here: <a href="http://meta.discourse.org/u/eviltrout/activity" class="inline-onebox-loading">http://meta.discourse.org/u/eviltrout/activity</a><br>next line.</li>\n</ol>`,
|
2013-08-23 06:03:01 +08:00
|
|
|
|
"allows autolinking within a list without inserting a paragraph."
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[3]: http://eviltrout.com",
|
|
|
|
|
"",
|
|
|
|
|
"It doesn't autolink markdown link references"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[]: http://eviltrout.com",
|
|
|
|
|
'<p>[]: <a href="http://eviltrout.com">http://eviltrout.com</a></p>',
|
|
|
|
|
"It doesn't accept empty link references"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[b]label[/b]: description",
|
|
|
|
|
'<p><span class="bbcode-b">label</span>: description</p>',
|
|
|
|
|
"It doesn't accept BBCode as link references"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"http://discourse.org and http://discourse.org/another_url and http://www.imdb.com/name/nm2225369",
|
2013-08-09 06:14:12 +08:00
|
|
|
|
'<p><a href="http://discourse.org">http://discourse.org</a> and ' +
|
2020-05-08 04:08:48 +08:00
|
|
|
|
`<a href="http://discourse.org/another_url" class="inline-onebox-loading">http://discourse.org/another_url</a> and ` +
|
|
|
|
|
`<a href="http://www.imdb.com/name/nm2225369" class="inline-onebox-loading">http://www.imdb.com/name/nm2225369</a></p>`,
|
2013-08-09 06:14:12 +08:00
|
|
|
|
"allows multiple links on one line"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"* [Evil Trout][1]\n\n[1]: http://eviltrout.com",
|
|
|
|
|
'<ul>\n<li><a href="http://eviltrout.com">Evil Trout</a></li>\n</ul>',
|
2013-08-29 01:06:41 +08:00
|
|
|
|
"allows markdown link references in a list"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"User [MOD]: Hello!",
|
2013-10-22 02:16:23 +08:00
|
|
|
|
"<p>User [MOD]: Hello!</p>",
|
|
|
|
|
"It does not consider references that are obviously not URLs"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"<small>http://eviltrout.com</small>",
|
|
|
|
|
'<p><small><a href="http://eviltrout.com">http://eviltrout.com</a></small></p>',
|
|
|
|
|
"Links within HTML tags"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[http://google.com ... wat](http://discourse.org)",
|
2014-07-15 02:26:48 +08:00
|
|
|
|
'<p><a href="http://discourse.org">http://google.com ... wat</a></p>',
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"it supports links within links"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[http://google.com](http://discourse.org)",
|
2016-10-30 08:30:36 +08:00
|
|
|
|
'<p><a href="http://discourse.org">http://google.com</a></p>',
|
|
|
|
|
"it supports markdown links where the name and link match"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
'[Link](http://www.example.com) (with an outer "description")',
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<p><a href="http://www.example.com">Link</a> (with an outer "description")</p>',
|
2014-09-23 04:51:48 +08:00
|
|
|
|
"it doesn't consume closing parens as part of the url"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"A link inside parentheses (http://www.example.com)",
|
2016-10-30 08:30:36 +08:00
|
|
|
|
'<p>A link inside parentheses (<a href="http://www.example.com">http://www.example.com</a>)</p>',
|
|
|
|
|
"it auto-links a url within parentheses"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[ul][1]\n\n[1]: http://eviltrout.com",
|
2015-01-01 00:44:56 +08:00
|
|
|
|
'<p><a href="http://eviltrout.com">ul</a></p>',
|
|
|
|
|
"it can use `ul` as a link name"
|
|
|
|
|
);
|
2013-06-19 06:03:36 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("simple quotes", assert => {
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"> nice!",
|
|
|
|
|
"<blockquote>\n<p>nice!</p>\n</blockquote>",
|
|
|
|
|
"it supports simple quotes"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
" > nice!",
|
|
|
|
|
"<blockquote>\n<p>nice!</p>\n</blockquote>",
|
|
|
|
|
"it allows quotes with preceding spaces"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"> level 1\n> > level 2",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"<blockquote>\n<p>level 1</p>\n<blockquote>\n<p>level 2</p>\n</blockquote>\n</blockquote>",
|
2013-08-30 03:18:27 +08:00
|
|
|
|
"it allows nesting of blockquotes"
|
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"> level 1\n> > level 2",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"<blockquote>\n<p>level 1</p>\n<blockquote>\n<p>level 2</p>\n</blockquote>\n</blockquote>",
|
2013-08-30 03:18:27 +08:00
|
|
|
|
"it allows nesting of blockquotes with spaces"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"- hello\n\n > world\n > eviltrout",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
`<ul>
|
|
|
|
|
<li>
|
|
|
|
|
<p>hello</p>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>world<br>
|
|
|
|
|
eviltrout</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>`,
|
2013-09-06 05:03:35 +08:00
|
|
|
|
"it allows quotes within a list."
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"- <p>eviltrout</p>",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"<ul>\n<li>\n<p>eviltrout</p></li>\n</ul>",
|
2014-07-16 04:41:53 +08:00
|
|
|
|
"it allows paragraphs within a list."
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
" > indent 1\n > indent 2",
|
|
|
|
|
"<blockquote>\n<p>indent 1<br>\nindent 2</p>\n</blockquote>",
|
|
|
|
|
"allow multiple spaces to indent"
|
|
|
|
|
);
|
2013-08-30 03:18:27 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Quotes", assert => {
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
'[quote="eviltrout, post: 1"]\na quote\n\nsecond line\n\nthird line\n[/quote]',
|
2013-08-22 10:36:02 +08:00
|
|
|
|
{ topicId: 2 },
|
2020-01-22 22:10:23 +08:00
|
|
|
|
`<aside class=\"quote no-group\" data-username=\"eviltrout\" data-post=\"1\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<div class=\"title\">
|
|
|
|
|
<div class=\"quote-controls\"></div>
|
|
|
|
|
eviltrout:</div>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>a quote</p>
|
|
|
|
|
<p>second line</p>
|
|
|
|
|
<p>third line</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>`,
|
2013-08-22 10:36:02 +08:00
|
|
|
|
"works with multiple lines"
|
|
|
|
|
);
|
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
'[quote="bob, post:1"]\nmy quote\n[/quote]',
|
2013-12-31 02:29:52 +08:00
|
|
|
|
{ topicId: 2, lookupAvatar: function() {} },
|
2020-01-22 22:10:23 +08:00
|
|
|
|
`<aside class=\"quote no-group\" data-username=\"bob\" data-post=\"1\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<div class=\"title\">
|
|
|
|
|
<div class=\"quote-controls\"></div>
|
|
|
|
|
bob:</div>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>my quote</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>`,
|
2013-06-19 06:03:36 +08:00
|
|
|
|
"includes no avatar if none is found"
|
|
|
|
|
);
|
2017-04-04 02:38:30 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
`[quote]\na\n\n[quote]\nb\n[/quote]\n[/quote]`,
|
2018-04-03 02:18:10 +08:00
|
|
|
|
`<aside class=\"quote no-group\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<blockquote>
|
|
|
|
|
<p>a</p>
|
2018-04-03 02:18:10 +08:00
|
|
|
|
<aside class=\"quote no-group\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<blockquote>
|
|
|
|
|
<p>b</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>`,
|
2017-04-04 02:38:30 +08:00
|
|
|
|
"handles nested quotes properly"
|
|
|
|
|
);
|
|
|
|
|
|
2017-11-03 21:51:40 +08:00
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
`[quote="bob, post:1, topic:1"]\ntest quote\n[/quote]`,
|
|
|
|
|
{ lookupPrimaryUserGroupByPostNumber: () => "aUserGroup" },
|
2020-01-22 22:10:23 +08:00
|
|
|
|
`<aside class="quote group-aUserGroup" data-username="bob" data-post="1" data-topic="1">
|
2017-11-03 21:51:40 +08:00
|
|
|
|
<div class="title">
|
|
|
|
|
<div class="quote-controls"></div>
|
|
|
|
|
bob:</div>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>test quote</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>`,
|
|
|
|
|
"quote has group class"
|
|
|
|
|
);
|
2013-06-27 06:41:48 +08:00
|
|
|
|
});
|
2013-06-19 06:03:36 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Mentions", assert => {
|
2018-11-22 14:28:48 +08:00
|
|
|
|
assert.cooked(
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"Hello @sam",
|
2018-11-22 14:28:48 +08:00
|
|
|
|
'<p>Hello <span class="mention">@sam</span></p>',
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"translates mentions to links"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[@codinghorror](https://twitter.com/codinghorror)",
|
|
|
|
|
'<p><a href="https://twitter.com/codinghorror">@codinghorror</a></p>',
|
2013-08-23 05:50:07 +08:00
|
|
|
|
"it doesn't do mentions within links"
|
|
|
|
|
);
|
|
|
|
|
|
2018-11-22 14:28:48 +08:00
|
|
|
|
assert.cooked(
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"[@codinghorror](https://twitter.com/codinghorror)",
|
2014-05-07 05:48:11 +08:00
|
|
|
|
'<p><a href="https://twitter.com/codinghorror">@codinghorror</a></p>',
|
|
|
|
|
"it doesn't do link mentions within links"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"Hello @EvilTrout",
|
2015-03-09 19:32:37 +08:00
|
|
|
|
'<p>Hello <span class="mention">@EvilTrout</span></p>',
|
|
|
|
|
"adds a mention class"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"robin@email.host",
|
2015-03-09 19:32:37 +08:00
|
|
|
|
"<p>robin@email.host</p>",
|
|
|
|
|
"won't add mention class to an email address"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"hanzo55@yahoo.com",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<p><a href="mailto:hanzo55@yahoo.com">hanzo55@yahoo.com</a></p>',
|
2015-03-09 19:32:37 +08:00
|
|
|
|
"won't be affected by email addresses that have a number before the @ symbol"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"@EvilTrout yo",
|
2015-03-09 19:32:37 +08:00
|
|
|
|
'<p><span class="mention">@EvilTrout</span> yo</p>',
|
|
|
|
|
"it handles mentions at the beginning of a string"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"yo\n@EvilTrout",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<p>yo<br>\n<span class="mention">@EvilTrout</span></p>',
|
2015-03-09 19:32:37 +08:00
|
|
|
|
"it handles mentions at the beginning of a new line"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"`evil` @EvilTrout `trout`",
|
2013-08-09 06:14:12 +08:00
|
|
|
|
'<p><code>evil</code> <span class="mention">@EvilTrout</span> <code>trout</code></p>',
|
2013-06-19 06:03:36 +08:00
|
|
|
|
"deals correctly with multiple <code> blocks"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```\na @test\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-auto">a @test\n</code></pre>',
|
2015-03-09 19:32:37 +08:00
|
|
|
|
"should not do mentions within a code block."
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"> foo bar baz @eviltrout",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<blockquote>\n<p>foo bar baz <span class="mention">@eviltrout</span></p>\n</blockquote>',
|
2013-08-22 04:10:16 +08:00
|
|
|
|
"handles mentions in simple quotes"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"> foo bar baz @eviltrout ohmagerd\nlook at this",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<blockquote>\n<p>foo bar baz <span class="mention">@eviltrout</span> ohmagerd<br>\nlook at this</p>\n</blockquote>',
|
2013-08-22 04:10:16 +08:00
|
|
|
|
"does mentions properly with trailing text within a simple quote"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"`code` is okay before @mention",
|
2013-08-23 00:18:03 +08:00
|
|
|
|
'<p><code>code</code> is okay before <span class="mention">@mention</span></p>',
|
2013-08-23 03:54:41 +08:00
|
|
|
|
"Does not mention in an inline code block"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"@mention is okay before `code`",
|
2013-08-23 00:18:03 +08:00
|
|
|
|
'<p><span class="mention">@mention</span> is okay before <code>code</code></p>',
|
2013-08-23 03:54:41 +08:00
|
|
|
|
"Does not mention in an inline code block"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"don't `@mention`",
|
2013-08-23 00:18:03 +08:00
|
|
|
|
"<p>don't <code>@mention</code></p>",
|
2013-08-23 03:54:41 +08:00
|
|
|
|
"Does not mention in an inline code block"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"Yes `@this` should be code @eviltrout",
|
2013-08-23 03:54:41 +08:00
|
|
|
|
'<p>Yes <code>@this</code> should be code <span class="mention">@eviltrout</span></p>',
|
|
|
|
|
"Does not mention in an inline code block"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"@eviltrout and `@eviltrout`",
|
2013-08-23 04:13:02 +08:00
|
|
|
|
'<p><span class="mention">@eviltrout</span> and <code>@eviltrout</code></p>',
|
|
|
|
|
"you can have a mention in an inline code block following a real mention."
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"1. this is a list\n\n2. this is an @eviltrout mention\n",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<ol>\n<li>\n<p>this is a list</p>\n</li>\n<li>\n<p>this is an <span class="mention">@eviltrout</span> mention</p>\n</li>\n</ol>',
|
2013-08-22 04:10:16 +08:00
|
|
|
|
"it mentions properly in a list."
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"Hello @foo/@bar",
|
2015-10-17 07:17:54 +08:00
|
|
|
|
'<p>Hello <span class="mention">@foo</span>/<span class="mention">@bar</span></p>',
|
|
|
|
|
"handles mentions separated by a slash."
|
|
|
|
|
);
|
|
|
|
|
|
2018-11-22 14:28:48 +08:00
|
|
|
|
assert.cooked(
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"<small>a @sam c</small>",
|
2018-11-22 14:28:48 +08:00
|
|
|
|
'<p><small>a <span class="mention">@sam</span> c</small></p>',
|
2014-07-04 04:54:56 +08:00
|
|
|
|
"it allows mentions within HTML tags"
|
|
|
|
|
);
|
2019-04-23 18:22:47 +08:00
|
|
|
|
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"@_sam @1sam @ab-cd.123_ABC-xYz @sam1",
|
|
|
|
|
'<p><span class="mention">@_sam</span> <span class="mention">@1sam</span> <span class="mention">@ab-cd.123_ABC-xYz</span> <span class="mention">@sam1</span></p>',
|
|
|
|
|
"it detects mentions of valid usernames"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"@.sam @-sam @sam. @sam_ @sam-",
|
|
|
|
|
'<p>@.sam @-sam <span class="mention">@sam</span>. <span class="mention">@sam</span>_ <span class="mention">@sam</span>-</p>',
|
|
|
|
|
"it does not detect mentions of invalid usernames"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"Hello @狮子",
|
|
|
|
|
{ siteSettings: { unicode_usernames: false } },
|
|
|
|
|
"<p>Hello @狮子</p>",
|
|
|
|
|
"it does not detect mentions of Unicode usernames"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QUnit.test("Mentions - Unicode usernames enabled", assert => {
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"Hello @狮子",
|
|
|
|
|
{ siteSettings: { unicode_usernames: true } },
|
|
|
|
|
'<p>Hello <span class="mention">@狮子</span></p>',
|
|
|
|
|
"it detects mentions of Unicode usernames"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"@狮子 @_狮子 @1狮子 @狮-ø.١٢٣_Ö-ழ் @狮子1",
|
|
|
|
|
{ siteSettings: { unicode_usernames: true } },
|
|
|
|
|
'<p><span class="mention">@狮子</span> <span class="mention">@_狮子</span> <span class="mention">@1狮子</span> <span class="mention">@狮-ø.١٢٣_Ö-ழ்</span> <span class="mention">@狮子1</span></p>',
|
|
|
|
|
"it detects mentions of valid Unicode usernames"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"@.狮子 @-狮子 @狮子. @狮子_ @狮子-",
|
|
|
|
|
{ siteSettings: { unicode_usernames: true } },
|
|
|
|
|
'<p>@.狮子 @-狮子 <span class="mention">@狮子</span>. <span class="mention">@狮子</span>_ <span class="mention">@狮子</span>-</p>',
|
|
|
|
|
"it does not detect mentions of invalid Unicode usernames"
|
|
|
|
|
);
|
2013-06-19 06:03:36 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-12-08 00:30:47 +08:00
|
|
|
|
QUnit.test("Mentions - disabled", assert => {
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"@eviltrout",
|
|
|
|
|
{ siteSettings: { enable_mentions: false } },
|
|
|
|
|
"<p>@eviltrout</p>"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Category hashtags", assert => {
|
2016-06-15 02:31:51 +08:00
|
|
|
|
const alwaysTrue = {
|
|
|
|
|
categoryHashtagLookup: function() {
|
2016-01-21 16:21:54 +08:00
|
|
|
|
return ["http://test.discourse.org/category-hashtag", "category-hashtag"];
|
2018-06-15 23:03:24 +08:00
|
|
|
|
}
|
2015-12-28 14:28:16 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"Check out #category-hashtag",
|
|
|
|
|
alwaysTrue,
|
|
|
|
|
'<p>Check out <a class="hashtag" href="http://test.discourse.org/category-hashtag">#<span>category-hashtag</span></a></p>',
|
2015-12-28 14:28:16 +08:00
|
|
|
|
"it translates category hashtag into links"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2015-12-28 14:28:16 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"Check out #category-hashtag",
|
|
|
|
|
'<p>Check out <span class="hashtag">#category-hashtag</span></p>',
|
|
|
|
|
"it does not translate category hashtag into links if it is not a valid category hashtag"
|
|
|
|
|
);
|
|
|
|
|
|
2018-01-11 03:11:14 +08:00
|
|
|
|
assert.cookedOptions(
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"[#category-hashtag](http://www.test.com)",
|
|
|
|
|
alwaysTrue,
|
2015-12-28 14:28:16 +08:00
|
|
|
|
'<p><a href="http://www.test.com">#category-hashtag</a></p>',
|
|
|
|
|
"it does not translate category hashtag within links"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```\n# #category-hashtag\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-auto"># #category-hashtag\n</code></pre>',
|
2015-12-28 14:28:16 +08:00
|
|
|
|
"it does not translate category hashtags to links in code blocks"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2018-01-11 03:11:14 +08:00
|
|
|
|
assert.cooked(
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"># #category-hashtag\n",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<blockquote>\n<h1><span class="hashtag">#category-hashtag</span></h1>\n</blockquote>',
|
2015-12-28 14:28:16 +08:00
|
|
|
|
"it handles category hashtags in simple quotes"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2018-01-25 01:33:38 +08:00
|
|
|
|
assert.cooked(
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"# #category-hashtag",
|
2015-12-28 14:28:16 +08:00
|
|
|
|
'<h1><span class="hashtag">#category-hashtag</span></h1>',
|
|
|
|
|
"it works within ATX-style headers"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2018-01-25 01:33:38 +08:00
|
|
|
|
assert.cooked(
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"don't `#category-hashtag`",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"<p>don't <code>#category-hashtag</code></p>",
|
2013-08-23 03:54:41 +08:00
|
|
|
|
"it does not mention in an inline code block"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"<small>#category-hashtag</small>",
|
2015-12-28 14:28:16 +08:00
|
|
|
|
'<p><small><span class="hashtag">#category-hashtag</span></small></p>',
|
|
|
|
|
"it works between HTML tags"
|
|
|
|
|
);
|
2018-12-27 00:42:40 +08:00
|
|
|
|
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"Checkout #ụdị",
|
|
|
|
|
'<p>Checkout <span class="hashtag">#ụdị</span></p>',
|
|
|
|
|
"it works for non-english characters"
|
|
|
|
|
);
|
2015-12-28 14:28:16 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Heading", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"**Bold**\n----------",
|
|
|
|
|
"<h2><strong>Bold</strong></h2>",
|
|
|
|
|
"It will bold the heading"
|
|
|
|
|
);
|
2014-07-26 03:59:16 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("bold and italics", assert => {
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
'a "**hello**"',
|
|
|
|
|
"<p>a "<strong>hello</strong>"</p>",
|
|
|
|
|
"bolds in quotes"
|
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"(**hello**)",
|
|
|
|
|
"<p>(<strong>hello</strong>)</p>",
|
|
|
|
|
"bolds in parens"
|
|
|
|
|
);
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"**hello**\nworld",
|
|
|
|
|
"<p><strong>hello</strong><br>\nworld</p>",
|
|
|
|
|
"allows newline after bold"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"**hello**\n**world**",
|
|
|
|
|
"<p><strong>hello</strong><br>\n<strong>world</strong></p>",
|
|
|
|
|
"newline between two bolds"
|
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"** hello**",
|
|
|
|
|
"<p>** hello**</p>",
|
|
|
|
|
"does not bold on a space boundary"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"**hello **",
|
|
|
|
|
"<p>**hello **</p>",
|
|
|
|
|
"does not bold on a space boundary"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"**你hello**",
|
|
|
|
|
"<p><strong>你hello</strong></p>",
|
|
|
|
|
"allows bolded chinese"
|
|
|
|
|
);
|
2013-10-16 22:39:06 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Escaping", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"*\\*laughs\\**",
|
|
|
|
|
"<p><em>*laughs*</em></p>",
|
|
|
|
|
"allows escaping strong"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"*\\_laughs\\_*",
|
|
|
|
|
"<p><em>_laughs_</em></p>",
|
|
|
|
|
"allows escaping em"
|
|
|
|
|
);
|
2014-09-23 04:51:48 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("New Lines", assert => {
|
2017-07-14 20:27:28 +08:00
|
|
|
|
// historically we would not continue inline em or b across lines,
|
|
|
|
|
// however commonmark gives us no switch to do so and we would be very non compliant.
|
|
|
|
|
// turning softbreaks into a newline is just a renderer option, not a parser switch.
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"_abc\ndef_",
|
|
|
|
|
"<p><em>abc<br>\ndef</em></p>",
|
|
|
|
|
"it does allow inlines to span new lines"
|
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"_abc\n\ndef_",
|
|
|
|
|
"<p>_abc</p>\n<p>def_</p>",
|
|
|
|
|
"it does not allow inlines to span new paragraphs"
|
|
|
|
|
);
|
2014-07-26 04:07:42 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Oneboxing", assert => {
|
2016-06-15 02:31:51 +08:00
|
|
|
|
function matches(input, regexp) {
|
|
|
|
|
return new PrettyText(defaultOpts).cook(input).match(regexp);
|
2013-06-19 06:03:36 +08:00
|
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.ok(
|
|
|
|
|
!matches(
|
|
|
|
|
"- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org",
|
2018-11-26 09:21:38 +08:00
|
|
|
|
/class="onebox"/
|
2017-06-15 01:57:58 +08:00
|
|
|
|
),
|
2013-08-09 06:14:12 +08:00
|
|
|
|
"doesn't onebox a link within a list"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.ok(
|
2018-11-26 09:21:38 +08:00
|
|
|
|
matches("http://test.com", /class="onebox"/),
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"adds a onebox class to a link on its own line"
|
|
|
|
|
);
|
|
|
|
|
assert.ok(
|
|
|
|
|
matches("http://test.com\nhttp://test2.com", /onebox[\s\S]+onebox/m),
|
|
|
|
|
"supports multiple links"
|
|
|
|
|
);
|
|
|
|
|
assert.ok(
|
|
|
|
|
!matches("http://test.com bob", /onebox/),
|
|
|
|
|
"doesn't onebox links that have trailing text"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.ok(
|
|
|
|
|
!matches("[Tom Cruise](http://www.tomcruise.com/)", "onebox"),
|
|
|
|
|
"Markdown links with labels are not oneboxed"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.ok(
|
|
|
|
|
!matches(
|
|
|
|
|
"[http://www.tomcruise.com/](http://www.tomcruise.com/)",
|
2013-09-07 04:46:55 +08:00
|
|
|
|
"onebox"
|
|
|
|
|
),
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"Markdown links where the label is the same as the url but link is explicit"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street",
|
2013-08-09 06:14:12 +08:00
|
|
|
|
'<p><a href="http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street" class="onebox"' +
|
2013-09-12 03:52:37 +08:00
|
|
|
|
' target="_blank">http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street</a></p>',
|
2013-06-19 06:03:36 +08:00
|
|
|
|
"works with links that have underscores in them"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("links with full urls", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"[http://eviltrout.com][1] is a url\n\n[1]: http://eviltrout.com",
|
2013-11-05 03:24:40 +08:00
|
|
|
|
'<p><a href="http://eviltrout.com">http://eviltrout.com</a> is a url</p>',
|
|
|
|
|
"it supports links that are full URLs"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("Code Blocks", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"<pre>\nhello\n</pre>\n",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"<pre>\nhello\n</pre>",
|
2014-06-24 03:21:07 +08:00
|
|
|
|
"pre blocks don't include extra lines"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```\na\nb\nc\n\nd\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-auto">a\nb\nc\n\nd\n</code></pre>',
|
2013-08-23 01:46:51 +08:00
|
|
|
|
"it treats new lines properly"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```\ntest\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-auto">test\n</code></pre>',
|
2013-08-09 06:14:12 +08:00
|
|
|
|
"it supports basic code blocks"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```json\n{hello: 'world'}\n```\ntrailing",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"<pre><code class=\"lang-json\">{hello: 'world'}\n</code></pre>\n<p>trailing</p>",
|
2013-08-09 06:14:12 +08:00
|
|
|
|
"It does not truncate text after a code block."
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```json\nline 1\n\nline 2\n\n\nline3\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-json">line 1\n\nline 2\n\n\nline3\n</code></pre>',
|
2013-08-09 06:14:12 +08:00
|
|
|
|
"it maintains new lines inside a code block."
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"hello\nworld\n```json\nline 1\n\nline 2\n\n\nline3\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<p>hello<br>\nworld</p>\n<pre><code class="lang-json">line 1\n\nline 2\n\n\nline3\n</code></pre>',
|
2013-08-09 06:14:12 +08:00
|
|
|
|
"it maintains new lines inside a code block with leading content."
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```ruby\n<header>hello</header>\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-ruby"><header>hello</header>\n</code></pre>',
|
2013-08-09 06:14:12 +08:00
|
|
|
|
"it escapes code in the code block"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```text\ntext\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-nohighlight">text\n</code></pre>',
|
2015-03-09 19:32:37 +08:00
|
|
|
|
"handles text by adding nohighlight"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```ruby\n# cool\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-ruby"># cool\n</code></pre>',
|
2013-08-09 06:14:12 +08:00
|
|
|
|
"it supports changing the language"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
" ```\n hello\n ```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"<pre><code>```\nhello\n```</code></pre>",
|
2014-10-20 06:55:19 +08:00
|
|
|
|
"only detect ``` at the beginning of lines"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```ruby\ndef self.parse(text)\n\n text\nend\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-ruby">def self.parse(text)\n\n text\nend\n</code></pre>',
|
2013-08-25 01:24:27 +08:00
|
|
|
|
"it allows leading spaces on lines in a code block."
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```ruby\nhello `eviltrout`\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-ruby">hello `eviltrout`\n</code></pre>',
|
2013-08-27 04:53:10 +08:00
|
|
|
|
"it allows code with backticks in it"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```eviltrout\nhello\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-auto">hello\n</code></pre>',
|
2013-10-22 01:10:19 +08:00
|
|
|
|
"it doesn't not whitelist all classes"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
'```\n[quote="sam, post:1, topic:9441, full:true"]This is `<not>` a bug.[/quote]\n```',
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-auto">[quote="sam, post:1, topic:9441, full:true"]This is `<not>` a bug.[/quote]\n</code></pre>',
|
2013-08-30 02:42:31 +08:00
|
|
|
|
"it allows code with backticks in it"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
" hello\n<blockquote>test</blockquote>",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"<pre><code>hello\n</code></pre>\n<blockquote>test</blockquote>",
|
2014-01-22 05:18:20 +08:00
|
|
|
|
"it allows an indented code block to by followed by a `<blockquote>`"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"``` foo bar ```",
|
2014-08-14 07:58:01 +08:00
|
|
|
|
"<p><code>foo bar</code></p>",
|
|
|
|
|
"it tolerates misuse of code block tags as inline code"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"```\nline1\n```\n```\nline2\n\nline3\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-auto">line1\n</code></pre>\n<pre><code class="lang-auto">line2\n\nline3\n</code></pre>',
|
2014-08-26 20:11:23 +08:00
|
|
|
|
"it does not consume next block's trailing newlines"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
" <pre>test</pre>",
|
2014-09-10 18:59:21 +08:00
|
|
|
|
"<pre><code><pre>test</pre></code></pre>",
|
|
|
|
|
"it does not parse other block types in markdown code blocks"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
" [quote]test[/quote]",
|
2014-09-10 18:59:21 +08:00
|
|
|
|
"<pre><code>[quote]test[/quote]</code></pre>",
|
|
|
|
|
"it does not parse other block types in markdown code blocks"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"## a\nb\n```\nc\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<h2>a</h2>\n<p>b</p>\n<pre><code class="lang-auto">c\n</code></pre>',
|
2015-03-09 19:32:37 +08:00
|
|
|
|
"it handles headings with code blocks after them."
|
|
|
|
|
);
|
2013-08-09 06:14:12 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("URLs in BBCode tags", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"[img]http://eviltrout.com/eviltrout.png[/img][img]http://samsaffron.com/samsaffron.png[/img]",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<p><img src="http://eviltrout.com/eviltrout.png" alt/><img src="http://samsaffron.com/samsaffron.png" alt/></p>',
|
2013-06-27 06:41:48 +08:00
|
|
|
|
"images are properly parsed"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[url]http://discourse.org[/url]",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<p><a href="http://discourse.org" data-bbcode="true">http://discourse.org</a></p>',
|
2013-06-27 06:41:48 +08:00
|
|
|
|
"links are properly parsed"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[url=http://discourse.org]discourse[/url]",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<p><a href="http://discourse.org" data-bbcode="true">discourse</a></p>',
|
2013-06-27 06:41:48 +08:00
|
|
|
|
"named links are properly parsed"
|
|
|
|
|
);
|
|
|
|
|
});
|
2013-10-12 04:24:27 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("images", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"[![folksy logo](http://folksy.com/images/folksy-colour.png)](http://folksy.com/)",
|
2014-02-21 04:23:10 +08:00
|
|
|
|
'<p><a href="http://folksy.com/"><img src="http://folksy.com/images/folksy-colour.png" alt="folksy logo"/></a></p>',
|
|
|
|
|
"It allows images with links around them"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
'<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot">',
|
2017-07-18 06:06:11 +08:00
|
|
|
|
'<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot"></p>',
|
2014-07-19 02:38:01 +08:00
|
|
|
|
"It allows data images"
|
|
|
|
|
);
|
2013-10-12 04:24:27 +08:00
|
|
|
|
});
|
2014-10-03 01:58:36 +08:00
|
|
|
|
|
2020-03-04 07:11:08 +08:00
|
|
|
|
QUnit.test("attachment", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"[test.pdf|attachment](upload://o8iobpLcW3WSFvVH7YQmyGlKmGM.pdf)",
|
|
|
|
|
`<p><a class="attachment" href="/404" data-orig-href="upload://o8iobpLcW3WSFvVH7YQmyGlKmGM.pdf">test.pdf</a></p>`,
|
|
|
|
|
"It returns the correct attachment link HTML"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QUnit.test("attachment - mapped url - secure media disabled", assert => {
|
|
|
|
|
function lookupUploadUrls() {
|
|
|
|
|
let cache = {};
|
|
|
|
|
cache["upload://o8iobpLcW3WSFvVH7YQmyGlKmGM.pdf"] = {
|
|
|
|
|
short_url: "upload://o8iobpLcW3WSFvVH7YQmyGlKmGM.pdf",
|
|
|
|
|
url:
|
|
|
|
|
"/secure-media-uploads/original/3X/c/b/o8iobpLcW3WSFvVH7YQmyGlKmGM.pdf",
|
|
|
|
|
short_path: "/uploads/short-url/blah"
|
|
|
|
|
};
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"[test.pdf|attachment](upload://o8iobpLcW3WSFvVH7YQmyGlKmGM.pdf)",
|
|
|
|
|
{
|
|
|
|
|
siteSettings: { secure_media: false },
|
|
|
|
|
lookupUploadUrls: lookupUploadUrls
|
|
|
|
|
},
|
|
|
|
|
`<p><a class="attachment" href="/uploads/short-url/blah">test.pdf</a></p>`,
|
|
|
|
|
"It returns the correct attachment link HTML when the URL is mapped without secure media"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QUnit.test("attachment - mapped url - secure media enabled", assert => {
|
|
|
|
|
function lookupUploadUrls() {
|
|
|
|
|
let cache = {};
|
|
|
|
|
cache["upload://o8iobpLcW3WSFvVH7YQmyGlKmGM.pdf"] = {
|
|
|
|
|
short_url: "upload://o8iobpLcW3WSFvVH7YQmyGlKmGM.pdf",
|
|
|
|
|
url:
|
|
|
|
|
"/secure-media-uploads/original/3X/c/b/o8iobpLcW3WSFvVH7YQmyGlKmGM.pdf",
|
|
|
|
|
short_path: "/uploads/short-url/blah"
|
|
|
|
|
};
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"[test.pdf|attachment](upload://o8iobpLcW3WSFvVH7YQmyGlKmGM.pdf)",
|
|
|
|
|
{
|
|
|
|
|
siteSettings: { secure_media: true },
|
|
|
|
|
lookupUploadUrls: lookupUploadUrls
|
|
|
|
|
},
|
|
|
|
|
`<p><a class="attachment" href="/secure-media-uploads/original/3X/c/b/o8iobpLcW3WSFvVH7YQmyGlKmGM.pdf">test.pdf</a></p>`,
|
|
|
|
|
"It returns the correct attachment link HTML when the URL is mapped with secure media"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-02-11 09:49:58 +08:00
|
|
|
|
QUnit.test("video - secure media enabled", assert => {
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"![baby shark|video](upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp4)",
|
|
|
|
|
{ siteSettings: { secure_media: true } },
|
|
|
|
|
`<p><div class="video-container">
|
2020-06-17 18:38:00 +08:00
|
|
|
|
<p class="video-description">baby shark</p>
|
2020-02-11 09:49:58 +08:00
|
|
|
|
<video width="100%" height="100%" preload="none" controls>
|
|
|
|
|
<source src="/404" data-orig-src="upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp4">
|
|
|
|
|
<a href="/404">/404</a>
|
|
|
|
|
</video>
|
|
|
|
|
</div></p>`,
|
|
|
|
|
"It returns the correct video player HTML"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QUnit.test("audio - secure media enabled", assert => {
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"![young americans|audio](upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp3)",
|
|
|
|
|
{ siteSettings: { secure_media: true } },
|
|
|
|
|
`<p><audio preload="none" controls>
|
|
|
|
|
<source src="/404" data-orig-src="upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp3">
|
|
|
|
|
<a href="/404">/404</a>
|
|
|
|
|
</audio></p>`,
|
|
|
|
|
"It returns the correct audio player HTML"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-01-23 07:41:39 +08:00
|
|
|
|
QUnit.test("video", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"![baby shark|video](upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp4)",
|
2020-01-29 13:52:02 +08:00
|
|
|
|
`<p><div class="video-container">
|
2020-06-17 18:38:00 +08:00
|
|
|
|
<p class="video-description">baby shark</p>
|
2020-02-11 09:49:58 +08:00
|
|
|
|
<video width="100%" height="100%" preload="metadata" controls>
|
2020-01-29 13:52:02 +08:00
|
|
|
|
<source src="/404" data-orig-src="upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp4">
|
|
|
|
|
<a href="/404">/404</a>
|
|
|
|
|
</video>
|
|
|
|
|
</div></p>`,
|
2020-01-23 07:41:39 +08:00
|
|
|
|
"It returns the correct video player HTML"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-03 12:44:01 +08:00
|
|
|
|
QUnit.test("video - mapped url - secure media enabled", assert => {
|
|
|
|
|
function lookupUploadUrls() {
|
|
|
|
|
let cache = {};
|
|
|
|
|
cache["upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp4"] = {
|
|
|
|
|
short_url: "upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp4",
|
|
|
|
|
url: "/secure-media-uploads/original/3X/c/b/test.mp4",
|
|
|
|
|
short_path: "/uploads/short-url/blah"
|
|
|
|
|
};
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"![baby shark|video](upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp4)",
|
|
|
|
|
{
|
|
|
|
|
siteSettings: { secure_media: true },
|
|
|
|
|
lookupUploadUrls: lookupUploadUrls
|
|
|
|
|
},
|
|
|
|
|
`<p><div class="video-container">
|
2020-06-17 18:38:00 +08:00
|
|
|
|
<p class="video-description">baby shark</p>
|
2020-03-03 12:44:01 +08:00
|
|
|
|
<video width="100%" height="100%" preload="none" controls>
|
|
|
|
|
<source src="/secure-media-uploads/original/3X/c/b/test.mp4">
|
|
|
|
|
<a href="/secure-media-uploads/original/3X/c/b/test.mp4">/secure-media-uploads/original/3X/c/b/test.mp4</a>
|
|
|
|
|
</video>
|
|
|
|
|
</div></p>`,
|
|
|
|
|
"It returns the correct video HTML when the URL is mapped with secure media, removing data-orig-src"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-01-23 07:41:39 +08:00
|
|
|
|
QUnit.test("audio", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"![young americans|audio](upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp3)",
|
2020-02-11 09:49:58 +08:00
|
|
|
|
`<p><audio preload="metadata" controls>
|
2020-01-23 07:41:39 +08:00
|
|
|
|
<source src="/404" data-orig-src="upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp3">
|
|
|
|
|
<a href="/404">/404</a>
|
|
|
|
|
</audio></p>`,
|
|
|
|
|
"It returns the correct audio player HTML"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-03 12:44:01 +08:00
|
|
|
|
QUnit.test("audio - mapped url - secure media enabled", assert => {
|
|
|
|
|
function lookupUploadUrls() {
|
|
|
|
|
let cache = {};
|
|
|
|
|
cache["upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp3"] = {
|
|
|
|
|
short_url: "upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp3",
|
|
|
|
|
url: "/secure-media-uploads/original/3X/c/b/test.mp3",
|
|
|
|
|
short_path: "/uploads/short-url/blah"
|
|
|
|
|
};
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"![baby shark|audio](upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp3)",
|
|
|
|
|
{
|
|
|
|
|
siteSettings: { secure_media: true },
|
|
|
|
|
lookupUploadUrls: lookupUploadUrls
|
|
|
|
|
},
|
|
|
|
|
`<p><audio preload="none" controls>
|
|
|
|
|
<source src="/secure-media-uploads/original/3X/c/b/test.mp3">
|
|
|
|
|
<a href="/secure-media-uploads/original/3X/c/b/test.mp3">/secure-media-uploads/original/3X/c/b/test.mp3</a>
|
|
|
|
|
</audio></p>`,
|
|
|
|
|
"It returns the correct audio HTML when the URL is mapped with secure media, removing data-orig-src"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("censoring", assert => {
|
2018-01-11 03:11:14 +08:00
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"Pleased to meet you, but pleeeease call me later, xyz123",
|
|
|
|
|
{
|
2019-08-01 01:33:49 +08:00
|
|
|
|
censoredRegexp: "(xyz*|plee+ase)"
|
2018-01-25 01:33:38 +08:00
|
|
|
|
},
|
2019-08-01 01:33:49 +08:00
|
|
|
|
"<p>Pleased to meet you, but ■■■■■■■■■ call me later, ■■■123</p>",
|
|
|
|
|
"supports censoring"
|
2018-01-11 03:11:14 +08:00
|
|
|
|
);
|
2019-08-01 01:33:49 +08:00
|
|
|
|
// More tests in pretty_text_spec.rb
|
2014-10-03 01:58:36 +08:00
|
|
|
|
});
|
2015-03-12 23:20:14 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("code blocks/spans hoisting", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"```\n\n some code\n```",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<pre><code class="lang-auto">\n some code\n</code></pre>',
|
2015-03-12 23:20:14 +08:00
|
|
|
|
"it works when nesting standard markdown code blocks within a fenced code block"
|
2017-07-14 20:27:28 +08:00
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"`$&`",
|
|
|
|
|
"<p><code>$&</code></p>",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"it works even when hoisting special replacement patterns"
|
|
|
|
|
);
|
2016-06-15 02:31:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("basic bbcode", assert => {
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[b]strong[/b]",
|
|
|
|
|
'<span class="bbcode-b">strong</span>',
|
|
|
|
|
"bolds text"
|
|
|
|
|
);
|
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[i]emphasis[/i]",
|
|
|
|
|
'<span class="bbcode-i">emphasis</span>',
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"italics text"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[u]underlined[/u]",
|
|
|
|
|
'<span class="bbcode-u">underlined</span>',
|
|
|
|
|
"underlines text"
|
|
|
|
|
);
|
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[s]strikethrough[/s]",
|
|
|
|
|
'<span class="bbcode-s">strikethrough</span>',
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"strikes-through text"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cookedPara(
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"[img]http://eviltrout.com/eviltrout.png[/img]",
|
|
|
|
|
'<img src="http://eviltrout.com/eviltrout.png" alt>',
|
|
|
|
|
"links images"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cookedPara(
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"[email]eviltrout@mailinator.com[/email]",
|
|
|
|
|
'<a href="mailto:eviltrout@mailinator.com" data-bbcode="true">eviltrout@mailinator.com</a>',
|
|
|
|
|
"supports [email] without a title"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[b]evil [i]trout[/i][/b]",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
'<span class="bbcode-b">evil <span class="bbcode-i">trout</span></span>',
|
|
|
|
|
"allows embedding of tags"
|
|
|
|
|
);
|
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[EMAIL]eviltrout@mailinator.com[/EMAIL]",
|
|
|
|
|
'<a href="mailto:eviltrout@mailinator.com" data-bbcode="true">eviltrout@mailinator.com</a>',
|
|
|
|
|
"supports upper case bbcode"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[b]strong [b]stronger[/b][/b]",
|
|
|
|
|
'<span class="bbcode-b">strong <span class="bbcode-b">stronger</span></span>',
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"accepts nested bbcode tags"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("urls", assert => {
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[url]not a url[/url]",
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"not a url",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"supports [url] that isn't a url"
|
|
|
|
|
);
|
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[url]abc.com[/url]",
|
|
|
|
|
'<a href="http://abc.com">abc.com</a>',
|
|
|
|
|
"it magically links using linkify"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cookedPara(
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"[url]http://bettercallsaul.com[/url]",
|
|
|
|
|
'<a href="http://bettercallsaul.com" data-bbcode="true">http://bettercallsaul.com</a>',
|
|
|
|
|
"supports [url] without parameter"
|
|
|
|
|
);
|
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[url=http://example.com]example[/url]",
|
|
|
|
|
'<a href="http://example.com" data-bbcode="true">example</a>',
|
|
|
|
|
"supports [url] with given href"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cookedPara(
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]",
|
|
|
|
|
'<a href="http://www.example.com" data-bbcode="true"><img src="http://example.com/logo.png" alt></a>',
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"supports [url] with an embedded [img]"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
QUnit.test("invalid bbcode", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"[code]I am not closed\n\nThis text exists.",
|
|
|
|
|
"<p>[code]I am not closed</p>\n<p>This text exists.</p>",
|
|
|
|
|
"does not raise an error with an open bbcode tag."
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("code", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"[code]\nx++\n[/code]",
|
|
|
|
|
'<pre><code class="lang-auto">x++</code></pre>',
|
|
|
|
|
"makes code into pre"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"[code]\nx++\ny++\nz++\n[/code]",
|
|
|
|
|
'<pre><code class="lang-auto">x++\ny++\nz++</code></pre>',
|
|
|
|
|
"makes code into pre"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[code]\nabc\n#def\n[/code]",
|
|
|
|
|
'<pre><code class="lang-auto">abc\n#def</code></pre>',
|
|
|
|
|
"it handles headings in a [code] block"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[code]\n s\n[/code]",
|
2016-06-15 02:31:51 +08:00
|
|
|
|
'<pre><code class="lang-auto"> s</code></pre>',
|
2017-06-15 01:57:58 +08:00
|
|
|
|
"it doesn't trim leading whitespace"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2016-06-15 02:31:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("tags with arguments", assert => {
|
|
|
|
|
assert.cookedPara(
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"[url=http://bettercallsaul.com]better call![/url]",
|
|
|
|
|
'<a href="http://bettercallsaul.com" data-bbcode="true">better call!</a>',
|
|
|
|
|
"supports [url] with a title"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cookedPara(
|
2017-07-14 20:27:28 +08:00
|
|
|
|
"[email=eviltrout@mailinator.com]evil trout[/email]",
|
|
|
|
|
'<a href="mailto:eviltrout@mailinator.com" data-bbcode="true">evil trout</a>',
|
|
|
|
|
"supports [email] with a title"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[u][i]abc[/i][/u]",
|
|
|
|
|
'<span class="bbcode-u"><span class="bbcode-i">abc</span></span>',
|
|
|
|
|
"can nest tags"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cookedPara(
|
|
|
|
|
"[b]first[/b] [b]second[/b]",
|
2016-06-15 02:31:51 +08:00
|
|
|
|
'<span class="bbcode-b">first</span> <span class="bbcode-b">second</span>',
|
2015-03-09 19:32:37 +08:00
|
|
|
|
"can bold two things on the same line"
|
2018-06-15 23:03:24 +08:00
|
|
|
|
);
|
|
|
|
|
});
|
2016-06-15 02:31:51 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("quotes", assert => {
|
2016-06-15 02:31:51 +08:00
|
|
|
|
const post = Post.create({
|
|
|
|
|
cooked: "<p><b>lorem</b> ipsum</p>",
|
|
|
|
|
username: "eviltrout",
|
|
|
|
|
post_number: 1,
|
|
|
|
|
topic_id: 2
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-08 22:28:23 +08:00
|
|
|
|
function formatQuote(val, expected, text, opts) {
|
|
|
|
|
assert.equal(buildQuote(post, val, opts), expected, text);
|
2016-06-15 02:31:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2016-06-15 02:31:51 +08:00
|
|
|
|
formatQuote(
|
|
|
|
|
" lorem \t ",
|
|
|
|
|
'[quote="eviltrout, post:1, topic:2"]\nlorem\n[/quote]\n\n',
|
|
|
|
|
"trims white spaces before & after the quoted contents"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2016-06-15 02:31:51 +08:00
|
|
|
|
formatQuote(
|
|
|
|
|
"lorem ipsum",
|
|
|
|
|
'[quote="eviltrout, post:1, topic:2, full:true"]\nlorem ipsum\n[/quote]\n\n',
|
2020-04-08 22:28:23 +08:00
|
|
|
|
"marks quotes as full if the `full` option is passed",
|
|
|
|
|
{ full: true }
|
2016-06-15 02:31:51 +08:00
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2016-06-15 02:31:51 +08:00
|
|
|
|
formatQuote(
|
|
|
|
|
"**lorem** ipsum",
|
2020-04-08 22:28:23 +08:00
|
|
|
|
'[quote="eviltrout, post:1, topic:2"]\n**lorem** ipsum\n[/quote]\n\n',
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"keeps BBCode formatting"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[quote]\ntest\n[/quote]",
|
2018-04-03 02:18:10 +08:00
|
|
|
|
'<aside class="quote no-group">\n<blockquote>\n<p>test</p>\n</blockquote>\n</aside>',
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"it supports quotes without params"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[quote]\n*test*\n[/quote]",
|
2018-04-03 02:18:10 +08:00
|
|
|
|
'<aside class="quote no-group">\n<blockquote>\n<p><em>test</em></p>\n</blockquote>\n</aside>',
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"it doesn't insert a new line for italics"
|
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[quote=,script='a'><script>alert('test');//':a]\n[/quote]",
|
2018-04-03 02:18:10 +08:00
|
|
|
|
'<aside class="quote no-group">\n<blockquote></blockquote>\n</aside>',
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"It will not create a script tag within an attribute"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-08 22:28:23 +08:00
|
|
|
|
QUnit.test("quoting a quote", assert => {
|
|
|
|
|
const post = Post.create({
|
|
|
|
|
cooked: new PrettyText(defaultOpts).cook(
|
|
|
|
|
'[quote="sam, post:1, topic:1, full:true"]\nhello\n[/quote]\n*Test*'
|
|
|
|
|
),
|
|
|
|
|
username: "eviltrout",
|
|
|
|
|
post_number: 1,
|
|
|
|
|
topic_id: 2
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const quote = buildQuote(
|
|
|
|
|
post,
|
|
|
|
|
'[quote="sam, post:1, topic:1, full:true"]\nhello\n[/quote]'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
|
quote,
|
|
|
|
|
'[quote="eviltrout, post:1, topic:2"]\n[quote="sam, post:1, topic:1, full:true"]\nhello\n[/quote]\n[/quote]\n\n',
|
|
|
|
|
"allows quoting a quote"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("quote formatting", assert => {
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
'[quote="EvilTrout, post:123, topic:456, full:true"]\n[sam]\n[/quote]',
|
2020-01-22 22:10:23 +08:00
|
|
|
|
`<aside class=\"quote no-group\" data-username=\"EvilTrout\" data-post=\"123\" data-topic=\"456\" data-full=\"true\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<div class=\"title\">
|
|
|
|
|
<div class=\"quote-controls\"></div>
|
|
|
|
|
EvilTrout:</div>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>[sam]</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>`,
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"it allows quotes with [] inside"
|
|
|
|
|
);
|
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
'[quote="eviltrout, post:1, topic:1"]\nabc\n[/quote]',
|
2020-01-22 22:10:23 +08:00
|
|
|
|
`<aside class=\"quote no-group\" data-username=\"eviltrout\" data-post=\"1\" data-topic=\"1\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<div class=\"title\">
|
|
|
|
|
<div class=\"quote-controls\"></div>
|
|
|
|
|
eviltrout:</div>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>abc</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>`,
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"renders quotes properly"
|
|
|
|
|
);
|
|
|
|
|
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
'[quote="eviltrout, post:1, topic:1"]\nabc\n[/quote]\nhello',
|
2020-01-22 22:10:23 +08:00
|
|
|
|
`<aside class=\"quote no-group\" data-username=\"eviltrout\" data-post=\"1\" data-topic=\"1\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<div class=\"title\">
|
|
|
|
|
<div class=\"quote-controls\"></div>
|
|
|
|
|
eviltrout:</div>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>abc</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>
|
|
|
|
|
<p>hello</p>`,
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"handles new lines properly"
|
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
'[quote="Alice, post:1, topic:1"]\n[quote="Bob, post:2, topic:1"]\n[/quote]\n[/quote]',
|
2020-01-22 22:10:23 +08:00
|
|
|
|
`<aside class=\"quote no-group\" data-username=\"Alice\" data-post=\"1\" data-topic=\"1\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<div class=\"title\">
|
|
|
|
|
<div class=\"quote-controls\"></div>
|
|
|
|
|
Alice:</div>
|
|
|
|
|
<blockquote>
|
2020-01-22 22:10:23 +08:00
|
|
|
|
<aside class=\"quote no-group\" data-username=\"Bob\" data-post=\"2\" data-topic=\"1\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<div class=\"title\">
|
|
|
|
|
<div class=\"quote-controls\"></div>
|
|
|
|
|
Bob:</div>
|
|
|
|
|
<blockquote></blockquote>
|
|
|
|
|
</aside>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>`,
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"quotes can be nested"
|
|
|
|
|
);
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
'[quote="Alice, post:1, topic:1"]\n[quote="Bob, post:2, topic:1"]\n[/quote]',
|
2017-07-14 20:27:28 +08:00
|
|
|
|
`<p>[quote="Alice, post:1, topic:1"]</p>
|
2020-01-22 22:10:23 +08:00
|
|
|
|
<aside class=\"quote no-group\" data-username=\"Bob\" data-post=\"2\" data-topic=\"1\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<div class=\"title\">
|
|
|
|
|
<div class=\"quote-controls\"></div>
|
|
|
|
|
Bob:</div>
|
|
|
|
|
<blockquote></blockquote>
|
|
|
|
|
</aside>`,
|
|
|
|
|
|
|
|
|
|
"handles mismatched nested quote tags (non greedy)"
|
|
|
|
|
);
|
2016-06-15 02:31:51 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[quote=\"Alice, post:1, topic:1\"]\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
2020-01-22 22:10:23 +08:00
|
|
|
|
`<aside class=\"quote no-group\" data-username=\"Alice\" data-post=\"1\" data-topic=\"1\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<div class=\"title\">
|
|
|
|
|
<div class=\"quote-controls\"></div>
|
|
|
|
|
Alice:</div>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<pre><code class=\"lang-javascript\">var foo ='foo';
|
|
|
|
|
var bar = 'bar';
|
|
|
|
|
</code></pre>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>`,
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"quotes can have code blocks without leading newline"
|
|
|
|
|
);
|
2017-07-14 20:27:28 +08:00
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.cooked(
|
|
|
|
|
"[quote=\"Alice, post:1, topic:1\"]\n\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
2020-01-22 22:10:23 +08:00
|
|
|
|
`<aside class=\"quote no-group\" data-username=\"Alice\" data-post=\"1\" data-topic=\"1\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<div class=\"title\">
|
|
|
|
|
<div class=\"quote-controls\"></div>
|
|
|
|
|
Alice:</div>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<pre><code class=\"lang-javascript\">var foo ='foo';
|
|
|
|
|
var bar = 'bar';
|
|
|
|
|
</code></pre>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>`,
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"quotes can have code blocks with leading newline"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("quotes with trailing formatting", assert => {
|
2016-06-15 02:31:51 +08:00
|
|
|
|
const result = new PrettyText(defaultOpts).cook(
|
|
|
|
|
'[quote="EvilTrout, post:123, topic:456, full:true"]\nhello\n[/quote]\n*Test*'
|
|
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
|
assert.equal(
|
|
|
|
|
result,
|
2020-01-22 22:10:23 +08:00
|
|
|
|
`<aside class=\"quote no-group\" data-username=\"EvilTrout\" data-post=\"123\" data-topic=\"456\" data-full=\"true\">
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<div class=\"title\">
|
|
|
|
|
<div class=\"quote-controls\"></div>
|
|
|
|
|
EvilTrout:</div>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>hello</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</aside>
|
|
|
|
|
<p><em>Test</em></p>`,
|
2016-06-15 02:31:51 +08:00
|
|
|
|
"it allows trailing formatting"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("enable/disable features", assert => {
|
2017-07-14 20:27:28 +08:00
|
|
|
|
assert.cookedOptions("|a|\n--\n|a|", { features: { table: false } }, "");
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"|a|\n--\n|a|",
|
2017-11-13 15:09:24 +08:00
|
|
|
|
`<div class="md-table">
|
|
|
|
|
<table>
|
2017-07-14 20:27:28 +08:00
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>a</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>a</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
2017-11-13 15:09:24 +08:00
|
|
|
|
</table>
|
|
|
|
|
</div>`
|
|
|
|
|
);
|
2016-06-15 02:31:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("emoji", assert => {
|
|
|
|
|
assert.cooked(
|
|
|
|
|
":smile:",
|
2020-01-16 16:54:26 +08:00
|
|
|
|
`<p><img src="/images/emoji/emoji_one/smile.png?v=${v}" title=":smile:" class="emoji only-emoji" alt=":smile:"></p>`
|
2017-06-15 01:57:58 +08:00
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
":(",
|
2020-01-16 16:54:26 +08:00
|
|
|
|
`<p><img src="/images/emoji/emoji_one/frowning.png?v=${v}" title=":frowning:" class="emoji only-emoji" alt=":frowning:"></p>`
|
2017-06-15 01:57:58 +08:00
|
|
|
|
);
|
|
|
|
|
assert.cooked(
|
|
|
|
|
"8-)",
|
2020-01-16 16:54:26 +08:00
|
|
|
|
`<p><img src="/images/emoji/emoji_one/sunglasses.png?v=${v}" title=":sunglasses:" class="emoji only-emoji" alt=":sunglasses:"></p>`
|
2017-06-15 01:57:58 +08:00
|
|
|
|
);
|
2016-06-15 02:31:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-26 22:26:59 +08:00
|
|
|
|
QUnit.test("emoji - enable_inline_emoji_translation", assert => {
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"test:smile:test",
|
|
|
|
|
{ siteSettings: { enable_inline_emoji_translation: false } },
|
|
|
|
|
`<p>test:smile:test</p>`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
"test:smile:test",
|
|
|
|
|
{ siteSettings: { enable_inline_emoji_translation: true } },
|
2018-11-26 22:27:45 +08:00
|
|
|
|
`<p>test<img src="/images/emoji/emoji_one/smile.png?v=${v}" title=":smile:" class="emoji" alt=":smile:">test</p>`
|
2018-11-26 22:26:59 +08:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
|
QUnit.test("emoji - emojiSet", assert => {
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
":smile:",
|
2017-07-14 20:27:28 +08:00
|
|
|
|
{ siteSettings: { emoji_set: "twitter" } },
|
2020-01-16 16:54:26 +08:00
|
|
|
|
`<p><img src="/images/emoji/twitter/smile.png?v=${v}" title=":smile:" class="emoji only-emoji" alt=":smile:"></p>`
|
2016-06-15 02:31:51 +08:00
|
|
|
|
);
|
|
|
|
|
});
|
2019-12-09 22:20:03 +08:00
|
|
|
|
|
2020-03-31 02:16:10 +08:00
|
|
|
|
QUnit.test("emoji - registerEmoji", assert => {
|
|
|
|
|
registerEmoji("foo", "/foo.png");
|
|
|
|
|
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
":foo:",
|
|
|
|
|
{},
|
|
|
|
|
`<p><img src="/foo.png?v=${v}" title=":foo:" class="emoji emoji-custom only-emoji" alt=":foo:"></p>`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
registerEmoji("bar", "/bar.png", "baz");
|
|
|
|
|
|
|
|
|
|
assert.cookedOptions(
|
|
|
|
|
":bar:",
|
|
|
|
|
{},
|
|
|
|
|
`<p><img src="/bar.png?v=${v}" title=":bar:" class="emoji emoji-custom only-emoji" alt=":bar:"></p>`
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2019-12-09 22:20:03 +08:00
|
|
|
|
QUnit.test("extractDataAttribute", assert => {
|
|
|
|
|
assert.deepEqual(extractDataAttribute("foo="), ["data-foo", ""]);
|
|
|
|
|
assert.deepEqual(extractDataAttribute("foo=bar"), ["data-foo", "bar"]);
|
|
|
|
|
|
|
|
|
|
assert.notOk(extractDataAttribute("foo?=bar"));
|
|
|
|
|
assert.notOk(extractDataAttribute("https://discourse.org/?q=hello"));
|
|
|
|
|
});
|