mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
Feature: Change markdown engine to markdown it
This commit removes the old evilstreak markdownjs engine. - Adds specs to WhiteLister and changes it to stop using globals (Fixes large memory leak) - Fixes edge cases around bbcode handling - Removes mdtest which is no longer valid (to be replaced with CommonMark) - Updates MiniRacer to correct minor unmanaged memory leak - Fixes plugin specs
This commit is contained in:
@ -5,7 +5,7 @@ import { IMAGE_VERSION as v} from 'pretty-text/emoji';
|
||||
|
||||
QUnit.module("lib:pretty-text");
|
||||
|
||||
const defaultOpts = buildOptions({
|
||||
const rawOpts = {
|
||||
siteSettings: {
|
||||
enable_emoji: true,
|
||||
emoji_set: 'emoji_one',
|
||||
@ -15,7 +15,9 @@ const defaultOpts = buildOptions({
|
||||
censored_pattern: '\\d{3}-\\d{4}|tech\\w*'
|
||||
},
|
||||
getURL: url => url
|
||||
});
|
||||
};
|
||||
|
||||
const defaultOpts = buildOptions(rawOpts);
|
||||
|
||||
QUnit.assert.cooked = function(input, expected, message) {
|
||||
const actual = new PrettyText(defaultOpts).cook(input);
|
||||
@ -28,7 +30,8 @@ QUnit.assert.cooked = function(input, expected, message) {
|
||||
};
|
||||
|
||||
QUnit.assert.cookedOptions = function(input, opts, expected, message) {
|
||||
const actual = new PrettyText(_.merge({}, defaultOpts, opts)).cook(input);
|
||||
const merged = _.merge({}, rawOpts, opts);
|
||||
const actual = new PrettyText(buildOptions(merged)).cook(input);
|
||||
this.pushResult({
|
||||
result: actual === expected,
|
||||
actual,
|
||||
@ -41,12 +44,18 @@ QUnit.assert.cookedPara = function(input, expected, message) {
|
||||
QUnit.assert.cooked(input, `<p>${expected}</p>`, message);
|
||||
};
|
||||
|
||||
QUnit.test("buildOptions", assert => {
|
||||
assert.ok(buildOptions({ siteSettings: { allow_html_tables: true } }).features.table, 'tables enabled');
|
||||
assert.ok(!buildOptions({ siteSettings: { allow_html_tables: false } }).features.table, 'tables disabled');
|
||||
|
||||
assert.ok(buildOptions({ siteSettings: { enable_emoji: true } }).features.emoji, 'emoji enabled');
|
||||
assert.ok(!buildOptions({ siteSettings: { enable_emoji: false } }).features.emoji, 'emoji disabled');
|
||||
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");
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
QUnit.test("basic cooking", assert => {
|
||||
@ -69,10 +78,8 @@ QUnit.test("Nested bold and italics", assert => {
|
||||
|
||||
QUnit.test("Traditional Line Breaks", assert => {
|
||||
const input = "1\n2\n3";
|
||||
assert.cooked(input, "<p>1<br/>2<br/>3</p>", "automatically handles trivial newlines");
|
||||
|
||||
const result = new PrettyText({ traditionalMarkdownLinebreaks: true }).cook(input);
|
||||
assert.equal(result, "<p>1\n2\n3</p>");
|
||||
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>");
|
||||
});
|
||||
|
||||
QUnit.test("Unbalanced underscores", assert => {
|
||||
@ -81,15 +88,19 @@ QUnit.test("Unbalanced underscores", assert => {
|
||||
|
||||
QUnit.test("Line Breaks", assert => {
|
||||
assert.cooked("[] first choice\n[] second choice",
|
||||
"<p>[] first choice<br/>[] second choice</p>",
|
||||
"<p>[] first choice<br>\n[] second choice</p>",
|
||||
"it handles new lines correctly with [] options");
|
||||
|
||||
// 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>
|
||||
assert.cooked("<blockquote>evil</blockquote>\ntrout",
|
||||
"<blockquote>evil</blockquote>\n\n<p>trout</p>",
|
||||
"<blockquote>evil</blockquote>\ntrout",
|
||||
"it doesn't insert <br> after blockquotes");
|
||||
|
||||
assert.cooked("leading<blockquote>evil</blockquote>\ntrout",
|
||||
"leading<blockquote>evil</blockquote>\n\n<p>trout</p>",
|
||||
"<p>leading<blockquote>evil</blockquote><br>\ntrout</p>",
|
||||
"it doesn't insert <br> after blockquotes with leading text");
|
||||
});
|
||||
|
||||
@ -114,10 +125,6 @@ QUnit.test("Links", assert => {
|
||||
'<p>Derpy: <a href="http://derp.com?__test=1">http://derp.com?__test=1</a></p>',
|
||||
"works with double underscores in urls");
|
||||
|
||||
assert.cooked("Derpy: http://derp.com?_test_=1",
|
||||
'<p>Derpy: <a href="http://derp.com?_test_=1">http://derp.com?_test_=1</a></p>',
|
||||
"works with underscores in urls");
|
||||
|
||||
assert.cooked("Atwood: www.codinghorror.com",
|
||||
'<p>Atwood: <a href="http://www.codinghorror.com">www.codinghorror.com</a></p>',
|
||||
"autolinks something that begins with www");
|
||||
@ -139,11 +146,11 @@ QUnit.test("Links", assert => {
|
||||
"autolinks a URL with parentheses (like Wikipedia)");
|
||||
|
||||
assert.cooked("Here's a tweet:\nhttps://twitter.com/evil_trout/status/345954894420787200",
|
||||
"<p>Here's a tweet:<br/><a href=\"https://twitter.com/evil_trout/status/345954894420787200\" class=\"onebox\" target=\"_blank\">https://twitter.com/evil_trout/status/345954894420787200</a></p>",
|
||||
"<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>",
|
||||
"It doesn't strip the new line.");
|
||||
|
||||
assert.cooked("1. View @eviltrout's profile here: http://meta.discourse.org/u/eviltrout/activity<br/>next line.",
|
||||
"<ol><li>View <span class=\"mention\">@eviltrout</span>'s profile here: <a href=\"http://meta.discourse.org/u/eviltrout/activity\">http://meta.discourse.org/u/eviltrout/activity</a><br>next line.</li></ol>",
|
||||
"<ol>\n<li>View <span class=\"mention\">@eviltrout</span>'s profile here: <a href=\"http://meta.discourse.org/u/eviltrout/activity\">http://meta.discourse.org/u/eviltrout/activity</a><br>next line.</li>\n</ol>",
|
||||
"allows autolinking within a list without inserting a paragraph.");
|
||||
|
||||
assert.cooked("[3]: http://eviltrout.com", "", "It doesn't autolink markdown link references");
|
||||
@ -158,8 +165,8 @@ QUnit.test("Links", assert => {
|
||||
"<a href=\"http://www.imdb.com/name/nm2225369\">http://www.imdb.com/name/nm2225369</a></p>",
|
||||
'allows multiple links on one line');
|
||||
|
||||
assert.cooked("* [Evil Trout][1]\n [1]: http://eviltrout.com",
|
||||
"<ul><li><a href=\"http://eviltrout.com\">Evil Trout</a></li></ul>",
|
||||
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>",
|
||||
"allows markdown link references in a list");
|
||||
|
||||
assert.cooked("User [MOD]: Hello!",
|
||||
@ -178,7 +185,7 @@ QUnit.test("Links", assert => {
|
||||
|
||||
|
||||
assert.cooked("[Link](http://www.example.com) (with an outer \"description\")",
|
||||
"<p><a href=\"http://www.example.com\">Link</a> (with an outer \"description\")</p>",
|
||||
"<p><a href=\"http://www.example.com\">Link</a> (with an outer "description")</p>",
|
||||
"it doesn't consume closing parens as part of the url");
|
||||
|
||||
assert.cooked("A link inside parentheses (http://www.example.com)",
|
||||
@ -191,50 +198,76 @@ QUnit.test("Links", assert => {
|
||||
});
|
||||
|
||||
QUnit.test("simple quotes", assert => {
|
||||
assert.cooked("> nice!", "<blockquote><p>nice!</p></blockquote>", "it supports simple quotes");
|
||||
assert.cooked(" > nice!", "<blockquote><p>nice!</p></blockquote>", "it allows quotes with preceding spaces");
|
||||
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");
|
||||
assert.cooked("> level 1\n> > level 2",
|
||||
"<blockquote><p>level 1</p><blockquote><p>level 2</p></blockquote></blockquote>",
|
||||
"<blockquote>\n<p>level 1</p>\n<blockquote>\n<p>level 2</p>\n</blockquote>\n</blockquote>",
|
||||
"it allows nesting of blockquotes");
|
||||
assert.cooked("> level 1\n> > level 2",
|
||||
"<blockquote><p>level 1</p><blockquote><p>level 2</p></blockquote></blockquote>",
|
||||
"<blockquote>\n<p>level 1</p>\n<blockquote>\n<p>level 2</p>\n</blockquote>\n</blockquote>",
|
||||
"it allows nesting of blockquotes with spaces");
|
||||
|
||||
assert.cooked("- hello\n\n > world\n > eviltrout",
|
||||
"<ul><li>hello</li></ul>\n\n<blockquote><p>world<br/>eviltrout</p></blockquote>",
|
||||
`<ul>
|
||||
<li>
|
||||
<p>hello</p>
|
||||
<blockquote>
|
||||
<p>world<br>
|
||||
eviltrout</p>
|
||||
</blockquote>
|
||||
</li>
|
||||
</ul>`,
|
||||
"it allows quotes within a list.");
|
||||
|
||||
assert.cooked("- <p>eviltrout</p>",
|
||||
"<ul><li><p>eviltrout</p></li></ul>",
|
||||
"<ul>\n<li>\n<p>eviltrout</p></li>\n</ul>",
|
||||
"it allows paragraphs within a list.");
|
||||
|
||||
|
||||
assert.cooked(" > indent 1\n > indent 2", "<blockquote><p>indent 1<br/>indent 2</p></blockquote>", "allow multiple spaces to indent");
|
||||
assert.cooked(" > indent 1\n > indent 2", "<blockquote>\n<p>indent 1<br>\nindent 2</p>\n</blockquote>", "allow multiple spaces to indent");
|
||||
|
||||
});
|
||||
|
||||
QUnit.test("Quotes", assert => {
|
||||
|
||||
assert.cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n\nthird line[/quote]",
|
||||
assert.cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n\nthird line\n[/quote]",
|
||||
{ topicId: 2 },
|
||||
"<aside class=\"quote\" data-post=\"1\"><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>",
|
||||
`<aside class=\"quote\" data-post=\"1\">
|
||||
<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>`,
|
||||
"works with multiple lines");
|
||||
|
||||
assert.cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||
{ topicId: 2, lookupAvatar: function(name) { return "" + name; }, sanitize: true },
|
||||
"<p>1</p>\n\n<aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>bob" +
|
||||
"bob:</div><blockquote><p>my quote</p></blockquote></aside>\n\n<p>2</p>",
|
||||
"handles quotes properly");
|
||||
|
||||
assert.cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||
assert.cookedOptions("[quote=\"bob, post:1\"]\nmy quote\n[/quote]",
|
||||
{ topicId: 2, lookupAvatar: function() { } },
|
||||
"<p>1</p>\n\n<aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>bob:" +
|
||||
"</div><blockquote><p>my quote</p></blockquote></aside>\n\n<p>2</p>",
|
||||
`<aside class=\"quote\" data-post=\"1\">
|
||||
<div class=\"title\">
|
||||
<div class=\"quote-controls\"></div>
|
||||
bob:</div>
|
||||
<blockquote>
|
||||
<p>my quote</p>
|
||||
</blockquote>
|
||||
</aside>`,
|
||||
"includes no avatar if none is found");
|
||||
|
||||
assert.cooked(`[quote]\na\n\n[quote]\nb\n[/quote]\n[/quote]`,
|
||||
"<p><aside class=\"quote\"><blockquote><p>a</p><p><aside class=\"quote\"><blockquote><p>b</p></blockquote></aside></p></blockquote></aside></p>",
|
||||
`<aside class=\"quote\">
|
||||
<blockquote>
|
||||
<p>a</p>
|
||||
<aside class=\"quote\">
|
||||
<blockquote>
|
||||
<p>b</p>
|
||||
</blockquote>
|
||||
</aside>
|
||||
</blockquote>
|
||||
</aside>`,
|
||||
"handles nested quotes properly");
|
||||
|
||||
});
|
||||
@ -264,7 +297,7 @@ QUnit.test("Mentions", assert => {
|
||||
"won't add mention class to an email address");
|
||||
|
||||
assert.cooked("hanzo55@yahoo.com",
|
||||
"<p>hanzo55@yahoo.com</p>",
|
||||
"<p><a href=\"mailto:hanzo55@yahoo.com\">hanzo55@yahoo.com</a></p>",
|
||||
"won't be affected by email addresses that have a number before the @ symbol");
|
||||
|
||||
assert.cooked("@EvilTrout yo",
|
||||
@ -272,7 +305,7 @@ QUnit.test("Mentions", assert => {
|
||||
"it handles mentions at the beginning of a string");
|
||||
|
||||
assert.cooked("yo\n@EvilTrout",
|
||||
"<p>yo<br/><span class=\"mention\">@EvilTrout</span></p>",
|
||||
"<p>yo<br>\n<span class=\"mention\">@EvilTrout</span></p>",
|
||||
"it handles mentions at the beginning of a new line");
|
||||
|
||||
assert.cooked("`evil` @EvilTrout `trout`",
|
||||
@ -280,15 +313,15 @@ QUnit.test("Mentions", assert => {
|
||||
"deals correctly with multiple <code> blocks");
|
||||
|
||||
assert.cooked("```\na @test\n```",
|
||||
"<p><pre><code class=\"lang-auto\">a @test</code></pre></p>",
|
||||
"<pre><code class=\"lang-auto\">a @test\n</code></pre>",
|
||||
"should not do mentions within a code block.");
|
||||
|
||||
assert.cooked("> foo bar baz @eviltrout",
|
||||
"<blockquote><p>foo bar baz <span class=\"mention\">@eviltrout</span></p></blockquote>",
|
||||
"<blockquote>\n<p>foo bar baz <span class=\"mention\">@eviltrout</span></p>\n</blockquote>",
|
||||
"handles mentions in simple quotes");
|
||||
|
||||
assert.cooked("> foo bar baz @eviltrout ohmagerd\nlook at this",
|
||||
"<blockquote><p>foo bar baz <span class=\"mention\">@eviltrout</span> ohmagerd<br/>look at this</p></blockquote>",
|
||||
"<blockquote>\n<p>foo bar baz <span class=\"mention\">@eviltrout</span> ohmagerd<br>\nlook at this</p>\n</blockquote>",
|
||||
"does mentions properly with trailing text within a simple quote");
|
||||
|
||||
assert.cooked("`code` is okay before @mention",
|
||||
@ -312,7 +345,7 @@ QUnit.test("Mentions", assert => {
|
||||
"you can have a mention in an inline code block following a real mention.");
|
||||
|
||||
assert.cooked("1. this is a list\n\n2. this is an @eviltrout mention\n",
|
||||
"<ol><li><p>this is a list</p></li><li><p>this is an <span class=\"mention\">@eviltrout</span> mention</p></li></ol>",
|
||||
"<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>",
|
||||
"it mentions properly in a list.");
|
||||
|
||||
assert.cooked("Hello @foo/@bar",
|
||||
@ -344,11 +377,11 @@ QUnit.test("Category hashtags", assert => {
|
||||
"it does not translate category hashtag within links");
|
||||
|
||||
assert.cooked("```\n# #category-hashtag\n```",
|
||||
"<p><pre><code class=\"lang-auto\"># #category-hashtag</code></pre></p>",
|
||||
"<pre><code class=\"lang-auto\"># #category-hashtag\n</code></pre>",
|
||||
"it does not translate category hashtags to links in code blocks");
|
||||
|
||||
assert.cooked("># #category-hashtag\n",
|
||||
"<blockquote><h1><span class=\"hashtag\">#category-hashtag</span></h1></blockquote>",
|
||||
"<blockquote>\n<h1><span class=\"hashtag\">#category-hashtag</span></h1>\n</blockquote>",
|
||||
"it handles category hashtags in simple quotes");
|
||||
|
||||
assert.cooked("# #category-hashtag",
|
||||
@ -359,10 +392,6 @@ QUnit.test("Category hashtags", assert => {
|
||||
"<p>don't <code>#category-hashtag</code></p>",
|
||||
"it does not mention in an inline code block");
|
||||
|
||||
assert.cooked("test #hashtag1/#hashtag2",
|
||||
"<p>test <span class=\"hashtag\">#hashtag1</span>/#hashtag2</p>",
|
||||
"it does not convert category hashtag not bounded by spaces");
|
||||
|
||||
assert.cooked("<small>#category-hashtag</small>",
|
||||
"<p><small><span class=\"hashtag\">#category-hashtag</span></small></p>",
|
||||
"it works between HTML tags");
|
||||
@ -374,14 +403,12 @@ QUnit.test("Heading", assert => {
|
||||
});
|
||||
|
||||
QUnit.test("bold and italics", assert => {
|
||||
assert.cooked("a \"**hello**\"", "<p>a \"<strong>hello</strong>\"</p>", "bolds in quotes");
|
||||
assert.cooked("a \"**hello**\"", "<p>a "<strong>hello</strong>"</p>", "bolds in quotes");
|
||||
assert.cooked("(**hello**)", "<p>(<strong>hello</strong>)</p>", "bolds in parens");
|
||||
assert.cooked("**hello**\nworld", "<p><strong>hello</strong><br>world</p>", "allows newline after bold");
|
||||
assert.cooked("**hello**\n**world**", "<p><strong>hello</strong><br><strong>world</strong></p>", "newline between two bolds");
|
||||
assert.cooked("**a*_b**", "<p><strong>a*_b</strong></p>", "allows for characters within bold");
|
||||
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");
|
||||
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>你**hello**</p>", "does not bold chinese intra word");
|
||||
assert.cooked("**你hello**", "<p><strong>你hello</strong></p>", "allows bolded chinese");
|
||||
});
|
||||
|
||||
@ -391,10 +418,11 @@ QUnit.test("Escaping", assert => {
|
||||
});
|
||||
|
||||
QUnit.test("New Lines", assert => {
|
||||
// Note: This behavior was discussed and we determined it does not make sense to do this
|
||||
// unless you're using traditional line breaks
|
||||
assert.cooked("_abc\ndef_", "<p>_abc<br>def_</p>", "it does not allow markup to span new lines");
|
||||
assert.cooked("_abc\n\ndef_", "<p>_abc</p>\n\n<p>def_</p>", "it does not allow markup to span new paragraphs");
|
||||
// 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");
|
||||
});
|
||||
|
||||
QUnit.test("Oneboxing", assert => {
|
||||
@ -411,9 +439,9 @@ QUnit.test("Oneboxing", assert => {
|
||||
assert.ok(!matches("http://test.com bob", /onebox/), "doesn't onebox links that have trailing text");
|
||||
|
||||
assert.ok(!matches("[Tom Cruise](http://www.tomcruise.com/)", "onebox"), "Markdown links with labels are not oneboxed");
|
||||
assert.ok(matches("[http://www.tomcruise.com/](http://www.tomcruise.com/)",
|
||||
assert.ok(!matches("[http://www.tomcruise.com/](http://www.tomcruise.com/)",
|
||||
"onebox"),
|
||||
"Markdown links where the label is the same as the url are oneboxed");
|
||||
"Markdown links where the label is the same as the url but link is explicit");
|
||||
|
||||
assert.cooked("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street",
|
||||
"<p><a href=\"http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street\" class=\"onebox\"" +
|
||||
@ -431,63 +459,63 @@ QUnit.test("links with full urls", assert => {
|
||||
QUnit.test("Code Blocks", assert => {
|
||||
|
||||
assert.cooked("<pre>\nhello\n</pre>\n",
|
||||
"<p><pre>hello</pre></p>",
|
||||
"<pre>\nhello\n</pre>",
|
||||
"pre blocks don't include extra lines");
|
||||
|
||||
assert.cooked("```\na\nb\nc\n\nd\n```",
|
||||
"<p><pre><code class=\"lang-auto\">a\nb\nc\n\nd</code></pre></p>",
|
||||
"<pre><code class=\"lang-auto\">a\nb\nc\n\nd\n</code></pre>",
|
||||
"it treats new lines properly");
|
||||
|
||||
assert.cooked("```\ntest\n```",
|
||||
"<p><pre><code class=\"lang-auto\">test</code></pre></p>",
|
||||
"<pre><code class=\"lang-auto\">test\n</code></pre>",
|
||||
"it supports basic code blocks");
|
||||
|
||||
assert.cooked("```json\n{hello: 'world'}\n```\ntrailing",
|
||||
"<p><pre><code class=\"lang-json\">{hello: 'world'}</code></pre></p>\n\n<p>trailing</p>",
|
||||
"<pre><code class=\"lang-json\">{hello: 'world'}\n</code></pre>\n<p>trailing</p>",
|
||||
"It does not truncate text after a code block.");
|
||||
|
||||
assert.cooked("```json\nline 1\n\nline 2\n\n\nline3\n```",
|
||||
"<p><pre><code class=\"lang-json\">line 1\n\nline 2\n\n\nline3</code></pre></p>",
|
||||
"<pre><code class=\"lang-json\">line 1\n\nline 2\n\n\nline3\n</code></pre>",
|
||||
"it maintains new lines inside a code block.");
|
||||
|
||||
assert.cooked("hello\nworld\n```json\nline 1\n\nline 2\n\n\nline3\n```",
|
||||
"<p>hello<br/>world<br/></p>\n\n<p><pre><code class=\"lang-json\">line 1\n\nline 2\n\n\nline3</code></pre></p>",
|
||||
"<p>hello<br>\nworld</p>\n<pre><code class=\"lang-json\">line 1\n\nline 2\n\n\nline3\n</code></pre>",
|
||||
"it maintains new lines inside a code block with leading content.");
|
||||
|
||||
assert.cooked("```ruby\n<header>hello</header>\n```",
|
||||
"<p><pre><code class=\"lang-ruby\"><header>hello</header></code></pre></p>",
|
||||
"<pre><code class=\"lang-ruby\"><header>hello</header>\n</code></pre>",
|
||||
"it escapes code in the code block");
|
||||
|
||||
assert.cooked("```text\ntext\n```",
|
||||
"<p><pre><code class=\"lang-nohighlight\">text</code></pre></p>",
|
||||
"<pre><code class=\"lang-nohighlight\">text\n</code></pre>",
|
||||
"handles text by adding nohighlight");
|
||||
|
||||
assert.cooked("```ruby\n# cool\n```",
|
||||
"<p><pre><code class=\"lang-ruby\"># cool</code></pre></p>",
|
||||
"<pre><code class=\"lang-ruby\"># cool\n</code></pre>",
|
||||
"it supports changing the language");
|
||||
|
||||
assert.cooked(" ```\n hello\n ```",
|
||||
"<pre><code>```\nhello\n```</code></pre>",
|
||||
"<pre><code>```\nhello\n```</code></pre>",
|
||||
"only detect ``` at the beginning of lines");
|
||||
|
||||
assert.cooked("```ruby\ndef self.parse(text)\n\n text\nend\n```",
|
||||
"<p><pre><code class=\"lang-ruby\">def self.parse(text)\n\n text\nend</code></pre></p>",
|
||||
"<pre><code class=\"lang-ruby\">def self.parse(text)\n\n text\nend\n</code></pre>",
|
||||
"it allows leading spaces on lines in a code block.");
|
||||
|
||||
assert.cooked("```ruby\nhello `eviltrout`\n```",
|
||||
"<p><pre><code class=\"lang-ruby\">hello `eviltrout`</code></pre></p>",
|
||||
"<pre><code class=\"lang-ruby\">hello `eviltrout`\n</code></pre>",
|
||||
"it allows code with backticks in it");
|
||||
|
||||
assert.cooked("```eviltrout\nhello\n```",
|
||||
"<p><pre><code class=\"lang-auto\">hello</code></pre></p>",
|
||||
"<pre><code class=\"lang-auto\">hello\n</code></pre>",
|
||||
"it doesn't not whitelist all classes");
|
||||
|
||||
assert.cooked("```\n[quote=\"sam, post:1, topic:9441, full:true\"]This is `<not>` a bug.[/quote]\n```",
|
||||
"<p><pre><code class=\"lang-auto\">[quote="sam, post:1, topic:9441, full:true"]This is `<not>` a bug.[/quote]</code></pre></p>",
|
||||
"<pre><code class=\"lang-auto\">[quote="sam, post:1, topic:9441, full:true"]This is `<not>` a bug.[/quote]\n</code></pre>",
|
||||
"it allows code with backticks in it");
|
||||
|
||||
assert.cooked(" hello\n<blockquote>test</blockquote>",
|
||||
"<pre><code>hello</code></pre>\n\n<blockquote>test</blockquote>",
|
||||
"<pre><code>hello\n</code></pre>\n<blockquote>test</blockquote>",
|
||||
"it allows an indented code block to by followed by a `<blockquote>`");
|
||||
|
||||
assert.cooked("``` foo bar ```",
|
||||
@ -495,7 +523,7 @@ QUnit.test("Code Blocks", assert => {
|
||||
"it tolerates misuse of code block tags as inline code");
|
||||
|
||||
assert.cooked("```\nline1\n```\n```\nline2\n\nline3\n```",
|
||||
"<p><pre><code class=\"lang-auto\">line1</code></pre></p>\n\n<p><pre><code class=\"lang-auto\">line2\n\nline3</code></pre></p>",
|
||||
"<pre><code class=\"lang-auto\">line1\n</code></pre>\n<pre><code class=\"lang-auto\">line2\n\nline3\n</code></pre>",
|
||||
"it does not consume next block's trailing newlines");
|
||||
|
||||
assert.cooked(" <pre>test</pre>",
|
||||
@ -507,22 +535,22 @@ QUnit.test("Code Blocks", assert => {
|
||||
"it does not parse other block types in markdown code blocks");
|
||||
|
||||
assert.cooked("## a\nb\n```\nc\n```",
|
||||
"<h2>a</h2>\n\n<p><pre><code class=\"lang-auto\">c</code></pre></p>",
|
||||
"<h2>a</h2>\n<p>b</p>\n<pre><code class=\"lang-auto\">c\n</code></pre>",
|
||||
"it handles headings with code blocks after them.");
|
||||
});
|
||||
|
||||
QUnit.test("URLs in BBCode tags", assert => {
|
||||
|
||||
assert.cooked("[img]http://eviltrout.com/eviltrout.png[/img][img]http://samsaffron.com/samsaffron.png[/img]",
|
||||
"<p><img src=\"http://eviltrout.com/eviltrout.png\"/><img src=\"http://samsaffron.com/samsaffron.png\"/></p>",
|
||||
"<p><img src=\"http://eviltrout.com/eviltrout.png\" alt/><img src=\"http://samsaffron.com/samsaffron.png\" alt/></p>",
|
||||
"images are properly parsed");
|
||||
|
||||
assert.cooked("[url]http://discourse.org[/url]",
|
||||
"<p><a href=\"http://discourse.org\">http://discourse.org</a></p>",
|
||||
"<p><a href=\"http://discourse.org\" data-bbcode=\"true\">http://discourse.org</a></p>",
|
||||
"links are properly parsed");
|
||||
|
||||
assert.cooked("[url=http://discourse.org]discourse[/url]",
|
||||
"<p><a href=\"http://discourse.org\">discourse</a></p>",
|
||||
"<p><a href=\"http://discourse.org\" data-bbcode=\"true\">discourse</a></p>",
|
||||
"named links are properly parsed");
|
||||
|
||||
});
|
||||
@ -533,39 +561,39 @@ QUnit.test("images", assert => {
|
||||
"It allows images with links around them");
|
||||
|
||||
assert.cooked("<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\">",
|
||||
"<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\"></p>",
|
||||
"<p>\n<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\"></p>",
|
||||
"It allows data images");
|
||||
});
|
||||
|
||||
QUnit.test("censoring", assert => {
|
||||
assert.cooked("aw shucks, golly gee whiz.",
|
||||
"<p>aw ■■■■■■, golly gee ■■■■.</p>",
|
||||
"<p>aw ■■■■■■, golly gee ■■■■.</p>",
|
||||
"it censors words in the Site Settings");
|
||||
|
||||
assert.cooked("you are a whizzard! I love cheesewhiz. Whiz.",
|
||||
"<p>you are a whizzard! I love cheesewhiz. ■■■■.</p>",
|
||||
"<p>you are a whizzard! I love cheesewhiz. ■■■■.</p>",
|
||||
"it doesn't censor words unless they have boundaries.");
|
||||
|
||||
assert.cooked("you are a whizzer! I love cheesewhiz. Whiz.",
|
||||
"<p>you are a ■■■■■■■! I love cheesewhiz. ■■■■.</p>",
|
||||
"<p>you are a ■■■■■■■! I love cheesewhiz. ■■■■.</p>",
|
||||
"it censors words even if previous partial matches exist.");
|
||||
|
||||
assert.cooked("The link still works. [whiz](http://www.whiz.com)",
|
||||
"<p>The link still works. <a href=\"http://www.whiz.com\">■■■■</a></p>",
|
||||
"<p>The link still works. <a href=\"http://www.whiz.com\">■■■■</a></p>",
|
||||
"it won't break links by censoring them.");
|
||||
|
||||
assert.cooked("Call techapj the computer whiz at 555-555-1234 for free help.",
|
||||
"<p>Call ■■■■■■■ the computer ■■■■ at 555-■■■■■■■■ for free help.</p>",
|
||||
"<p>Call ■■■■■■■ the computer ■■■■ at 555-■■■■■■■■ for free help.</p>",
|
||||
"uses both censored words and patterns from site settings");
|
||||
|
||||
assert.cooked("I have a pen, I have an a**le",
|
||||
"<p>I have a pen, I have an ■■■■■</p>",
|
||||
"<p>I have a pen, I have an ■■■■■</p>",
|
||||
"it escapes regexp chars");
|
||||
});
|
||||
|
||||
QUnit.test("code blocks/spans hoisting", assert => {
|
||||
assert.cooked("```\n\n some code\n```",
|
||||
"<p><pre><code class=\"lang-auto\"> some code</code></pre></p>",
|
||||
"<pre><code class=\"lang-auto\">\n some code\n</code></pre>",
|
||||
"it works when nesting standard markdown code blocks within a fenced code block");
|
||||
|
||||
assert.cooked("`$&`",
|
||||
@ -578,47 +606,42 @@ QUnit.test('basic bbcode', assert => {
|
||||
assert.cookedPara("[i]emphasis[/i]", "<span class=\"bbcode-i\">emphasis</span>", "italics text");
|
||||
assert.cookedPara("[u]underlined[/u]", "<span class=\"bbcode-u\">underlined</span>", "underlines text");
|
||||
assert.cookedPara("[s]strikethrough[/s]", "<span class=\"bbcode-s\">strikethrough</span>", "strikes-through text");
|
||||
assert.cookedPara("[img]http://eviltrout.com/eviltrout.png[/img]", "<img src=\"http://eviltrout.com/eviltrout.png\">", "links images");
|
||||
assert.cookedPara("[email]eviltrout@mailinator.com[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>", "supports [email] without a title");
|
||||
assert.cookedPara("[img]http://eviltrout.com/eviltrout.png[/img]", "<img src=\"http://eviltrout.com/eviltrout.png\" alt>", "links images");
|
||||
assert.cookedPara("[email]eviltrout@mailinator.com[/email]", "<a href=\"mailto:eviltrout@mailinator.com\" data-bbcode=\"true\">eviltrout@mailinator.com</a>", "supports [email] without a title");
|
||||
assert.cookedPara("[b]evil [i]trout[/i][/b]",
|
||||
"<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\">eviltrout@mailinator.com</a>", "supports upper case bbcode");
|
||||
assert.cookedPara("[EMAIL]eviltrout@mailinator.com[/EMAIL]", "<a href=\"mailto:eviltrout@mailinator.com\" data-bbcode=\"true\">eviltrout@mailinator.com</a>", "supports upper case bbcode");
|
||||
assert.cookedPara("[b]strong [b]stronger[/b][/b]", "<span class=\"bbcode-b\">strong <span class=\"bbcode-b\">stronger</span></span>", "accepts nested bbcode tags");
|
||||
});
|
||||
|
||||
QUnit.test('urls', assert => {
|
||||
assert.cookedPara("[url]not a url[/url]", "not a url", "supports [url] that isn't a url");
|
||||
assert.cookedPara("[url]abc.com[/url]", "abc.com", "no error when a url has no protocol and begins with a");
|
||||
assert.cookedPara("[url]http://bettercallsaul.com[/url]", "<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>", "supports [url] without parameter");
|
||||
assert.cookedPara("[url=http://example.com]example[/url]", "<a href=\"http://example.com\">example</a>", "supports [url] with given href");
|
||||
assert.cookedPara("[url]abc.com[/url]", "<a href=\"http://abc.com\">abc.com</a>", "it magically links using linkify");
|
||||
assert.cookedPara("[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");
|
||||
assert.cookedPara("[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]",
|
||||
"<a href=\"http://www.example.com\"><img src=\"http://example.com/logo.png\"></a>",
|
||||
"<a href=\"http://www.example.com\" data-bbcode=\"true\"><img src=\"http://example.com/logo.png\" alt></a>",
|
||||
"supports [url] with an embedded [img]");
|
||||
});
|
||||
QUnit.test('invalid bbcode', assert => {
|
||||
const result = new PrettyText({ lookupAvatar: false }).cook("[code]I am not closed\n\nThis text exists.");
|
||||
assert.equal(result, "<p>[code]I am not closed</p>\n\n<p>This text exists.</p>", "does not raise an error with an open bbcode tag.");
|
||||
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.");
|
||||
});
|
||||
|
||||
QUnit.test('code', assert => {
|
||||
assert.cookedPara("[code]\nx++\n[/code]", "<pre><code class=\"lang-auto\">x++</code></pre>", "makes code into pre");
|
||||
assert.cookedPara("[code]\nx++\ny++\nz++\n[/code]", "<pre><code class=\"lang-auto\">x++\ny++\nz++</code></pre>", "makes code into pre");
|
||||
assert.cookedPara("[code]abc\n#def\n[/code]", '<pre><code class=\"lang-auto\">abc\n#def</code></pre>', 'it handles headings in a [code] block');
|
||||
assert.cookedPara("[code]\n s[/code]",
|
||||
assert.cooked("[code]\nx++\n[/code]", "<pre><code class=\"lang-auto\">x++</code></pre>", "makes code into pre");
|
||||
assert.cooked("[code]\nx++\ny++\nz++\n[/code]", "<pre><code class=\"lang-auto\">x++\ny++\nz++</code></pre>", "makes code into pre");
|
||||
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');
|
||||
assert.cooked("[code]\n s\n[/code]",
|
||||
"<pre><code class=\"lang-auto\"> s</code></pre>",
|
||||
"it doesn't trim leading whitespace");
|
||||
});
|
||||
|
||||
QUnit.test('lists', assert => {
|
||||
assert.cookedPara("[ul][li]option one[/li][/ul]", "<ul><li>option one</li></ul>", "creates an ul");
|
||||
assert.cookedPara("[ol][li]option one[/li][/ol]", "<ol><li>option one</li></ol>", "creates an ol");
|
||||
assert.cookedPara("[ul]\n[li]option one[/li]\n[li]option two[/li]\n[/ul]", "<ul><li>option one</li><li>option two</li></ul>", "suppresses empty lines in lists");
|
||||
});
|
||||
|
||||
QUnit.test('tags with arguments', assert => {
|
||||
assert.cookedPara("[url=http://bettercallsaul.com]better call![/url]", "<a href=\"http://bettercallsaul.com\">better call!</a>", "supports [url] with a title");
|
||||
assert.cookedPara("[email=eviltrout@mailinator.com]evil trout[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>", "supports [email] with a title");
|
||||
assert.cookedPara("[url=http://bettercallsaul.com]better call![/url]", "<a href=\"http://bettercallsaul.com\" data-bbcode=\"true\">better call!</a>", "supports [url] with a title");
|
||||
assert.cookedPara("[email=eviltrout@mailinator.com]evil trout[/email]", "<a href=\"mailto:eviltrout@mailinator.com\" data-bbcode=\"true\">evil trout</a>", "supports [email] with a title");
|
||||
assert.cookedPara("[u][i]abc[/i][/u]", "<span class=\"bbcode-u\"><span class=\"bbcode-i\">abc</span></span>", "can nest tags");
|
||||
assert.cookedPara("[b]first[/b] [b]second[/b]", "<span class=\"bbcode-b\">first</span> <span class=\"bbcode-b\">second</span>", "can bold two things on the same line");
|
||||
});
|
||||
@ -658,70 +681,140 @@ QUnit.test("quotes", assert => {
|
||||
"[quote=\"eviltrout, post:1, topic:2\"]\nthis is <not> a bug\n[/quote]\n\n",
|
||||
"it escapes the contents of the quote");
|
||||
|
||||
assert.cookedPara("[quote]test[/quote]",
|
||||
"<aside class=\"quote\"><blockquote><p>test</p></blockquote></aside>",
|
||||
assert.cooked("[quote]\ntest\n[/quote]",
|
||||
"<aside class=\"quote\">\n<blockquote>\n<p>test</p>\n</blockquote>\n</aside>",
|
||||
"it supports quotes without params");
|
||||
|
||||
assert.cookedPara("[quote]\n*test*\n[/quote]",
|
||||
"<aside class=\"quote\"><blockquote><p><em>test</em></p></blockquote></aside>",
|
||||
assert.cooked("[quote]\n*test*\n[/quote]",
|
||||
"<aside class=\"quote\">\n<blockquote>\n<p><em>test</em></p>\n</blockquote>\n</aside>",
|
||||
"it doesn't insert a new line for italics");
|
||||
|
||||
assert.cookedPara("[quote=,script='a'><script>alert('test');//':a][/quote]",
|
||||
"<aside class=\"quote\"><blockquote></blockquote></aside>",
|
||||
assert.cooked("[quote=,script='a'><script>alert('test');//':a]\n[/quote]",
|
||||
"<aside class=\"quote\">\n<blockquote></blockquote>\n</aside>",
|
||||
"It will not create a script tag within an attribute");
|
||||
});
|
||||
|
||||
QUnit.test("quote formatting", assert => {
|
||||
|
||||
assert.cooked("[quote=\"EvilTrout, post:123, topic:456, full:true\"][sam][/quote]",
|
||||
"<aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\"><div class=\"title\">" +
|
||||
"<div class=\"quote-controls\"></div>EvilTrout:</div><blockquote><p>[sam]</p></blockquote></aside>",
|
||||
assert.cooked("[quote=\"EvilTrout, post:123, topic:456, full:true\"]\n[sam]\n[/quote]",
|
||||
`<aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\">
|
||||
<div class=\"title\">
|
||||
<div class=\"quote-controls\"></div>
|
||||
EvilTrout:</div>
|
||||
<blockquote>
|
||||
<p>[sam]</p>
|
||||
</blockquote>
|
||||
</aside>`,
|
||||
"it allows quotes with [] inside");
|
||||
|
||||
assert.cooked("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout:" +
|
||||
"</div><blockquote><p>abc</p></blockquote></aside>",
|
||||
assert.cooked("[quote=\"eviltrout, post:1, topic:1\"]\nabc\n[/quote]",
|
||||
`<aside class=\"quote\" data-post=\"1\" data-topic=\"1\">
|
||||
<div class=\"title\">
|
||||
<div class=\"quote-controls\"></div>
|
||||
eviltrout:</div>
|
||||
<blockquote>
|
||||
<p>abc</p>
|
||||
</blockquote>
|
||||
</aside>`,
|
||||
"renders quotes properly");
|
||||
|
||||
assert.cooked("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]\nhello",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout:" +
|
||||
"</div><blockquote><p>abc</p></blockquote></aside>\n\n<p>hello</p>",
|
||||
assert.cooked("[quote=\"eviltrout, post:1, topic:1\"]\nabc\n[/quote]\nhello",
|
||||
`<aside class=\"quote\" data-post=\"1\" data-topic=\"1\">
|
||||
<div class=\"title\">
|
||||
<div class=\"quote-controls\"></div>
|
||||
eviltrout:</div>
|
||||
<blockquote>
|
||||
<p>abc</p>
|
||||
</blockquote>
|
||||
</aside>
|
||||
<p>hello</p>`,
|
||||
"handles new lines properly");
|
||||
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n[quote=\"Bob, post:2, topic:1\"]\n[/quote]\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:" +
|
||||
"</div><blockquote><aside class=\"quote\" data-post=\"2\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Bob:" +
|
||||
"</div><blockquote></blockquote></aside></blockquote></aside>",
|
||||
`<aside class=\"quote\" data-post=\"1\" data-topic=\"1\">
|
||||
<div class=\"title\">
|
||||
<div class=\"quote-controls\"></div>
|
||||
Alice:</div>
|
||||
<blockquote>
|
||||
<aside class=\"quote\" data-post=\"2\" data-topic=\"1\">
|
||||
<div class=\"title\">
|
||||
<div class=\"quote-controls\"></div>
|
||||
Bob:</div>
|
||||
<blockquote></blockquote>
|
||||
</aside>
|
||||
</blockquote>
|
||||
</aside>`,
|
||||
"quotes can be nested");
|
||||
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n[quote=\"Bob, post:2, topic:1\"]\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:" +
|
||||
"</div><blockquote><p>[quote=\"Bob, post:2, topic:1\"]</p></blockquote></aside>",
|
||||
"handles mismatched nested quote tags");
|
||||
`<p>[quote="Alice, post:1, topic:1"]</p>
|
||||
<aside class=\"quote\" data-post=\"2\" data-topic=\"1\">
|
||||
<div class=\"title\">
|
||||
<div class=\"quote-controls\"></div>
|
||||
Bob:</div>
|
||||
<blockquote></blockquote>
|
||||
</aside>`,
|
||||
|
||||
"handles mismatched nested quote tags (non greedy)");
|
||||
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:</div><blockquote><p><pre><code class=\"lang-javascript\">var foo ='foo';\nvar bar = 'bar';</code></pre></p></blockquote></aside>",
|
||||
`<aside class=\"quote\" data-post=\"1\" data-topic=\"1\">
|
||||
<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>`,
|
||||
"quotes can have code blocks without leading newline");
|
||||
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:</div><blockquote><p><pre><code class=\"lang-javascript\">var foo ='foo';\nvar bar = 'bar';</code></pre></p></blockquote></aside>",
|
||||
`<aside class=\"quote\" data-post=\"1\" data-topic=\"1\">
|
||||
<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>`,
|
||||
"quotes can have code blocks with leading newline");
|
||||
});
|
||||
|
||||
QUnit.test("quotes with trailing formatting", assert => {
|
||||
const result = new PrettyText(defaultOpts).cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]\nhello\n[/quote]\n*Test*");
|
||||
assert.equal(result,
|
||||
"<aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\"><div class=\"title\">" +
|
||||
"<div class=\"quote-controls\"></div>EvilTrout:</div><blockquote><p>hello</p></blockquote></aside>\n\n<p><em>Test</em></p>",
|
||||
`<aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\">
|
||||
<div class=\"title\">
|
||||
<div class=\"quote-controls\"></div>
|
||||
EvilTrout:</div>
|
||||
<blockquote>
|
||||
<p>hello</p>
|
||||
</blockquote>
|
||||
</aside>
|
||||
<p><em>Test</em></p>`,
|
||||
"it allows trailing formatting");
|
||||
});
|
||||
|
||||
QUnit.test("enable/disable features", assert => {
|
||||
const table = `<table><tr><th>hello</th></tr><tr><td>world</td></tr></table>`;
|
||||
const hasTable = new PrettyText({ features: {table: true}, sanitize: true}).cook(table);
|
||||
assert.equal(hasTable, `<table class="md-table"><tr><th>hello</th></tr><tr><td>world</td></tr></table>`);
|
||||
|
||||
const noTable = new PrettyText({ features: { table: false }, sanitize: true}).cook(table);
|
||||
assert.equal(noTable, `<p></p>`, 'tables are stripped when disabled');
|
||||
assert.cookedOptions('|a|\n--\n|a|', { features: {table: false} }, '');
|
||||
assert.cooked('|a|\n--\n|a|',
|
||||
`<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>a</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>a</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>`);
|
||||
});
|
||||
|
||||
QUnit.test("emoji", assert => {
|
||||
@ -732,6 +825,6 @@ QUnit.test("emoji", assert => {
|
||||
|
||||
QUnit.test("emoji - emojiSet", assert => {
|
||||
assert.cookedOptions(":smile:",
|
||||
{ emojiSet: 'twitter' },
|
||||
{ siteSettings : { emoji_set: 'twitter' }},
|
||||
`<p><img src="/images/emoji/twitter/smile.png?v=${v}" title=":smile:" class="emoji" alt=":smile:"></p>`);
|
||||
});
|
||||
|
Reference in New Issue
Block a user