mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
fix(simpleAutoLinks): URLs with emphasis/strikethrough are parsed
correctly When a user enters a URL with emphasis or strikethrough, the html output were incorrect. Now, URLs inside emphasis or strikethrough are parsed corerctly Closes #347
This commit is contained in:
parent
1ebc1959dd
commit
5c50675cca
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -1,54 +1,74 @@
|
||||||
|
// url allowed chars [a-z\d_.~:/?#[]@!$&'()*+,;=-]
|
||||||
|
|
||||||
|
var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)()(?=\s|$)(?!["<>])/gi,
|
||||||
|
simpleURLRegex2 = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+?)([.!?()]?)(?=\s|$)(?!["<>])/gi,
|
||||||
|
//simpleURLRegex3 = /\b(((https?|ftp):\/\/|www\.)[a-z\d.-]+\.[a-z\d_.~:/?#\[\]@!$&'()*+,;=-]+?)([.!?()]?)(?=\s|$)(?!["<>])/gi,
|
||||||
|
delimUrlRegex = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
|
||||||
|
simpleMailRegex = /(^|\s)(?:mailto:)?([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?=$|\s)/gmi,
|
||||||
|
delimMailRegex = /<()(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi,
|
||||||
|
|
||||||
|
replaceLink = function (options) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
return function (wm, link, m2, m3, trailingPunctuation) {
|
||||||
|
var lnkTxt = link,
|
||||||
|
append = '';
|
||||||
|
if (/^www\./i.test(link)) {
|
||||||
|
link = link.replace(/^www\./i, 'http://www.');
|
||||||
|
}
|
||||||
|
if (options.excludeTrailingPunctuationFromURLs && trailingPunctuation) {
|
||||||
|
append = trailingPunctuation;
|
||||||
|
}
|
||||||
|
return '<a href="' + link + '">' + lnkTxt + '</a>' + append;
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
replaceMail = function (options, globals) {
|
||||||
|
'use strict';
|
||||||
|
return function (wholeMatch, b, mail) {
|
||||||
|
var href = 'mailto:';
|
||||||
|
b = b || '';
|
||||||
|
mail = showdown.subParser('unescapeSpecialChars')(mail, options, globals);
|
||||||
|
if (options.encodeEmails) {
|
||||||
|
href = showdown.helper.encodeEmailAddress(href + mail);
|
||||||
|
mail = showdown.helper.encodeEmailAddress(mail);
|
||||||
|
} else {
|
||||||
|
href = href + mail;
|
||||||
|
}
|
||||||
|
return b + '<a href="' + href + '">' + mail + '</a>';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
showdown.subParser('autoLinks', function (text, options, globals) {
|
showdown.subParser('autoLinks', function (text, options, globals) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
text = globals.converter._dispatch('autoLinks.before', text, options, globals);
|
text = globals.converter._dispatch('autoLinks.before', text, options, globals);
|
||||||
|
|
||||||
var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)()(?=\s|$)(?!["<>])/gi,
|
text = text.replace(delimUrlRegex, replaceLink(options));
|
||||||
simpleURLRegex2 = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+?)([.!?()]?)(?=\s|$)(?!["<>])/gi,
|
text = text.replace(delimMailRegex, replaceMail(options, globals));
|
||||||
delimUrlRegex = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
|
|
||||||
simpleMailRegex = /(^|\s)(?:mailto:)?([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?=$|\s)/gmi,
|
|
||||||
delimMailRegex = /<()(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
|
|
||||||
|
|
||||||
text = text.replace(delimUrlRegex, replaceLink);
|
|
||||||
text = text.replace(delimMailRegex, replaceMail);
|
|
||||||
// simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi,
|
|
||||||
// Email addresses: <address@domain.foo>
|
|
||||||
|
|
||||||
if (options.simplifiedAutoLink) {
|
|
||||||
if (options.excludeTrailingPunctuationFromURLs) {
|
|
||||||
text = text.replace(simpleURLRegex2, replaceLink);
|
|
||||||
} else {
|
|
||||||
text = text.replace(simpleURLRegex, replaceLink);
|
|
||||||
}
|
|
||||||
text = text.replace(simpleMailRegex, replaceMail);
|
|
||||||
}
|
|
||||||
|
|
||||||
function replaceLink (wm, link, m2, m3, trailingPunctuation) {
|
|
||||||
var lnkTxt = link,
|
|
||||||
append = '';
|
|
||||||
if (/^www\./i.test(link)) {
|
|
||||||
link = link.replace(/^www\./i, 'http://www.');
|
|
||||||
}
|
|
||||||
if (options.excludeTrailingPunctuationFromURLs && trailingPunctuation) {
|
|
||||||
append = trailingPunctuation;
|
|
||||||
}
|
|
||||||
return '<a href="' + link + '">' + lnkTxt + '</a>' + append;
|
|
||||||
}
|
|
||||||
|
|
||||||
function replaceMail (wholeMatch, b, mail) {
|
|
||||||
var href = 'mailto:';
|
|
||||||
b = b || '';
|
|
||||||
mail = showdown.subParser('unescapeSpecialChars')(mail, options, globals);
|
|
||||||
if (options.encodeEmails) {
|
|
||||||
href = showdown.helper.encodeEmailAddress(href + mail);
|
|
||||||
mail = showdown.helper.encodeEmailAddress(mail);
|
|
||||||
} else {
|
|
||||||
href = href + mail;
|
|
||||||
}
|
|
||||||
return b + '<a href="' + href + '">' + mail + '</a>';
|
|
||||||
}
|
|
||||||
|
|
||||||
text = globals.converter._dispatch('autoLinks.after', text, options, globals);
|
text = globals.converter._dispatch('autoLinks.after', text, options, globals);
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
showdown.subParser('simplifiedAutoLinks', function (text, options, globals) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
if (!options.simplifiedAutoLink) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
text = globals.converter._dispatch('simplifiedAutoLinks.before', text, options, globals);
|
||||||
|
|
||||||
|
if (options.excludeTrailingPunctuationFromURLs) {
|
||||||
|
text = text.replace(simpleURLRegex2, replaceLink(options));
|
||||||
|
} else {
|
||||||
|
text = text.replace(simpleURLRegex, replaceLink(options));
|
||||||
|
}
|
||||||
|
text = text.replace(simpleMailRegex, replaceMail(options, globals));
|
||||||
|
|
||||||
|
text = globals.converter._dispatch('simplifiedAutoLinks.after', text, options, globals);
|
||||||
|
|
||||||
|
return text;
|
||||||
|
});
|
||||||
|
|
|
@ -7,34 +7,47 @@ showdown.subParser('italicsAndBold', function (text, options, globals) {
|
||||||
// because of backtracing, in some cases, it could lead to an exponential effect
|
// because of backtracing, in some cases, it could lead to an exponential effect
|
||||||
// called "catastrophic backtrace". Ominous!
|
// called "catastrophic backtrace". Ominous!
|
||||||
|
|
||||||
|
function parseInside (txt, left, right) {
|
||||||
|
if (options.simplifiedAutoLink) {
|
||||||
|
txt = showdown.subParser('simplifiedAutoLinks')(txt, options, globals);
|
||||||
|
}
|
||||||
|
return left + txt + right;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse underscores
|
// Parse underscores
|
||||||
if (options.literalMidWordUnderscores) {
|
if (options.literalMidWordUnderscores) {
|
||||||
text = text.replace(/\b___(\S[\s\S]*)___\b/g, '<strong><em>$1</em></strong>');
|
text = text.replace(/\b___(\S[\s\S]*)___\b/g, function (wm, txt) {
|
||||||
text = text.replace(/\b__(\S[\s\S]*)__\b/g, '<strong>$1</strong>');
|
return parseInside (txt, '<strong><em>', '</em></strong>');
|
||||||
text = text.replace(/\b_(\S[\s\S]*?)_\b/g, '<em>$1</em>');
|
});
|
||||||
|
text = text.replace(/\b__(\S[\s\S]*)__\b/g, function (wm, txt) {
|
||||||
|
return parseInside (txt, '<strong>', '</strong>');
|
||||||
|
});
|
||||||
|
text = text.replace(/\b_(\S[\s\S]*?)_\b/g, function (wm, txt) {
|
||||||
|
return parseInside (txt, '<em>', '</em>');
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
text = text.replace(/___(\S[\s\S]*?)___/g, function (wm, m) {
|
text = text.replace(/___(\S[\s\S]*?)___/g, function (wm, m) {
|
||||||
return (/\S$/.test(m)) ? '<strong><em>' + m + '</em></strong>' : wm;
|
return (/\S$/.test(m)) ? parseInside (m, '<strong><em>', '</em></strong>') : wm;
|
||||||
});
|
});
|
||||||
text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) {
|
text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) {
|
||||||
return (/\S$/.test(m)) ? '<strong>' + m + '</strong>' : wm;
|
return (/\S$/.test(m)) ? parseInside (m, '<strong>', '</strong>') : wm;
|
||||||
});
|
});
|
||||||
text = text.replace(/_([^\s_][\s\S]*?)_/g, function (wm, m) {
|
text = text.replace(/_([^\s_][\s\S]*?)_/g, function (wm, m) {
|
||||||
// !/^_[^_]/.test(m) - test if it doesn't start with __ (since it seems redundant, we removed it)
|
// !/^_[^_]/.test(m) - test if it doesn't start with __ (since it seems redundant, we removed it)
|
||||||
return (/\S$/.test(m)) ? '<em>' + m + '</em>' : wm;
|
return (/\S$/.test(m)) ? parseInside (m, '<em>', '</em>') : wm;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now parse asterisks
|
// Now parse asterisks
|
||||||
text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) {
|
text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) {
|
||||||
return (/\S$/.test(m)) ? '<strong><em>' + m + '</em></strong>' : wm;
|
return (/\S$/.test(m)) ? parseInside (m, '<strong><em>', '</em></strong>') : wm;
|
||||||
});
|
});
|
||||||
text = text.replace(/\*\*(\S[\s\S]*?)\*\*/g, function (wm, m) {
|
text = text.replace(/\*\*(\S[\s\S]*?)\*\*/g, function (wm, m) {
|
||||||
return (/\S$/.test(m)) ? '<strong>' + m + '</strong>' : wm;
|
return (/\S$/.test(m)) ? parseInside (m, '<strong>', '</strong>') : wm;
|
||||||
});
|
});
|
||||||
text = text.replace(/\*([^\s*][\s\S]*?)\*/g, function (wm, m) {
|
text = text.replace(/\*([^\s*][\s\S]*?)\*/g, function (wm, m) {
|
||||||
// !/^\*[^*]/.test(m) - test if it doesn't start with ** (since it seems redundant, we removed it)
|
// !/^\*[^*]/.test(m) - test if it doesn't start with ** (since it seems redundant, we removed it)
|
||||||
return (/\S$/.test(m)) ? '<em>' + m + '</em>' : wm;
|
return (/\S$/.test(m)) ? parseInside (m, '<em>', '</em>') : wm;
|
||||||
});
|
});
|
||||||
|
|
||||||
text = globals.converter._dispatch('italicsAndBold.after', text, options, globals);
|
text = globals.converter._dispatch('italicsAndBold.after', text, options, globals);
|
||||||
|
|
|
@ -16,11 +16,12 @@ showdown.subParser('spanGamut', function (text, options, globals) {
|
||||||
text = showdown.subParser('anchors')(text, options, globals);
|
text = showdown.subParser('anchors')(text, options, globals);
|
||||||
|
|
||||||
// Make links out of things like `<http://example.com/>`
|
// Make links out of things like `<http://example.com/>`
|
||||||
// Must come after _DoAnchors(), because you can use < and >
|
// Must come after anchors, because you can use < and >
|
||||||
// delimiters in inline links like [this](<url>).
|
// delimiters in inline links like [this](<url>).
|
||||||
text = showdown.subParser('autoLinks')(text, options, globals);
|
text = showdown.subParser('autoLinks')(text, options, globals);
|
||||||
text = showdown.subParser('italicsAndBold')(text, options, globals);
|
text = showdown.subParser('italicsAndBold')(text, options, globals);
|
||||||
text = showdown.subParser('strikethrough')(text, options, globals);
|
text = showdown.subParser('strikethrough')(text, options, globals);
|
||||||
|
text = showdown.subParser('simplifiedAutoLinks')(text, options, globals);
|
||||||
|
|
||||||
// we need to hash HTML tags inside spans
|
// we need to hash HTML tags inside spans
|
||||||
text = showdown.subParser('hashHTMLSpans')(text, options, globals);
|
text = showdown.subParser('hashHTMLSpans')(text, options, globals);
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
showdown.subParser('strikethrough', function (text, options, globals) {
|
showdown.subParser('strikethrough', function (text, options, globals) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
function parseInside (txt) {
|
||||||
|
if (options.simplifiedAutoLink) {
|
||||||
|
txt = showdown.subParser('simplifiedAutoLinks')(txt, options, globals);
|
||||||
|
}
|
||||||
|
return '<del>' + txt + '</del>';
|
||||||
|
}
|
||||||
|
|
||||||
if (options.strikethrough) {
|
if (options.strikethrough) {
|
||||||
text = globals.converter._dispatch('strikethrough.before', text, options, globals);
|
text = globals.converter._dispatch('strikethrough.before', text, options, globals);
|
||||||
text = text.replace(/(?:~){2}([\s\S]+?)(?:~){2}/g, '<del>$1</del>');
|
text = text.replace(/(?:~){2}([\s\S]+?)(?:~){2}/g, function (wm, txt) { return parseInside(txt); });
|
||||||
text = globals.converter._dispatch('strikethrough.after', text, options, globals);
|
text = globals.converter._dispatch('strikethrough.after', text, options, globals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
test/features/simplifiedAutoLink/blockquote.html
Normal file
3
test/features/simplifiedAutoLink/blockquote.html
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<blockquote>
|
||||||
|
<p><a href="http://www.google.com">http://www.google.com</a></p>
|
||||||
|
</blockquote>
|
1
test/features/simplifiedAutoLink/blockquote.md
Normal file
1
test/features/simplifiedAutoLink/blockquote.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
> http://www.google.com
|
|
@ -0,0 +1 @@
|
||||||
|
<p><a href="http://www.google.com">www.google.com</a></p>
|
|
@ -0,0 +1 @@
|
||||||
|
<a href="http://www.google.com">www.google.com</a>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<pre><code>some code with
|
||||||
|
a link
|
||||||
|
www.google.com
|
||||||
|
|
||||||
|
and another link http://www.google.com
|
||||||
|
</code></pre>
|
|
@ -0,0 +1,5 @@
|
||||||
|
some code with
|
||||||
|
a link
|
||||||
|
www.google.com
|
||||||
|
|
||||||
|
and another link http://www.google.com
|
|
@ -0,0 +1,7 @@
|
||||||
|
<p><em><a href="http://www.google.com/foobar">http://www.google.com/foobar</a></em></p>
|
||||||
|
<p><strong><a href="http://www.google.com/foobar">http://www.google.com/foobar</a></strong></p>
|
||||||
|
<p><strong><em><a href="http://www.google.com/foobar">http://www.google.com/foobar</a></em></strong></p>
|
||||||
|
<p><del><a href="http://www.google.com/foobar">http://www.google.com/foobar</a></del></p>
|
||||||
|
<p><em><a href="http://www.google.com/foobar">http://www.google.com/foobar</a></em></p>
|
||||||
|
<p><strong><a href="http://www.google.com/foobar">http://www.google.com/foobar</a></strong></p>
|
||||||
|
<p><strong><em><a href="http://www.google.com/foobar">http://www.google.com/foobar</a></em></strong></p>
|
|
@ -0,0 +1,13 @@
|
||||||
|
*http://www.google.com/foobar*
|
||||||
|
|
||||||
|
**http://www.google.com/foobar**
|
||||||
|
|
||||||
|
***http://www.google.com/foobar***
|
||||||
|
|
||||||
|
~~http://www.google.com/foobar~~
|
||||||
|
|
||||||
|
_http://www.google.com/foobar_
|
||||||
|
|
||||||
|
__http://www.google.com/foobar__
|
||||||
|
|
||||||
|
___http://www.google.com/foobar___
|
11
test/features/simplifiedAutoLink/ordered-lists.html
Normal file
11
test/features/simplifiedAutoLink/ordered-lists.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<ol>
|
||||||
|
<li><a href="http://www.google.com/listitem1">http://www.google.com/listitem1</a></li>
|
||||||
|
<li><a href="http://www.google.com/listitem2">http://www.google.com/listitem2</a></li>
|
||||||
|
<li><a href="http://www.google.com/listitem3">http://www.google.com/listitem3</a></li>
|
||||||
|
</ol>
|
||||||
|
<p>foo</p>
|
||||||
|
<ol>
|
||||||
|
<li><p><a href="http://www.google.com/listitem1">http://www.google.com/listitem1</a></p></li>
|
||||||
|
<li><p><a href="http://www.google.com/listitem2">http://www.google.com/listitem2</a></p></li>
|
||||||
|
<li><p><a href="http://www.google.com/listitem3">http://www.google.com/listitem3</a></p></li>
|
||||||
|
</ol>
|
11
test/features/simplifiedAutoLink/ordered-lists.md
Normal file
11
test/features/simplifiedAutoLink/ordered-lists.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
1. http://www.google.com/listitem1
|
||||||
|
2. http://www.google.com/listitem2
|
||||||
|
3. http://www.google.com/listitem3
|
||||||
|
|
||||||
|
foo
|
||||||
|
|
||||||
|
1. http://www.google.com/listitem1
|
||||||
|
|
||||||
|
2. http://www.google.com/listitem2
|
||||||
|
|
||||||
|
3. http://www.google.com/listitem3
|
6
test/features/simplifiedAutoLink/text.html
Normal file
6
test/features/simplifiedAutoLink/text.html
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<p><a href="http://www.google.com/foobar">http://www.google.com/foobar</a></p>
|
||||||
|
<p><a href="http://www.google.com/foobar">www.google.com/foobar</a></p>
|
||||||
|
<p><a href="ftp://user:password@host.com:port/path">ftp://user:password@host.com:port/path</a></p>
|
||||||
|
<p>this has some <a href="http://www.google.com/foobar">http://www.google.com/foobar</a> in text</p>
|
||||||
|
<p>this has some <a href="http://www.google.com/foobar">www.google.com/foobar</a> in text</p>
|
||||||
|
<p>this has some <a href="ftp://user:password@host.com:port/path">ftp://user:password@host.com:port/path</a> in text</p>
|
13
test/features/simplifiedAutoLink/text.md
Normal file
13
test/features/simplifiedAutoLink/text.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
http://www.google.com/foobar
|
||||||
|
|
||||||
|
www.google.com/foobar
|
||||||
|
|
||||||
|
ftp://user:password@host.com:port/path
|
||||||
|
|
||||||
|
this has some http://www.google.com/foobar in text
|
||||||
|
|
||||||
|
this has some www.google.com/foobar in text
|
||||||
|
|
||||||
|
this has some ftp://user:password@host.com:port/path in text
|
||||||
|
|
||||||
|
|
11
test/features/simplifiedAutoLink/unordered-lists.html
Normal file
11
test/features/simplifiedAutoLink/unordered-lists.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<ul>
|
||||||
|
<li><a href="http://www.google.com/foo">http://www.google.com/foo</a></li>
|
||||||
|
<li><a href="http://www.google.com/bar">http://www.google.com/bar</a></li>
|
||||||
|
<li><a href="http://www.google.com/baz">http://www.google.com/baz</a></li>
|
||||||
|
</ul>
|
||||||
|
<p>a</p>
|
||||||
|
<ul>
|
||||||
|
<li><p><a href="http://www.google.com/foo">http://www.google.com/foo</a></p></li>
|
||||||
|
<li><p><a href="http://www.google.com/bar">http://www.google.com/bar</a></p></li>
|
||||||
|
<li><p><a href="http://www.google.com/baz">http://www.google.com/baz</a></p></li>
|
||||||
|
</ul>
|
11
test/features/simplifiedAutoLink/unordered-lists.md
Normal file
11
test/features/simplifiedAutoLink/unordered-lists.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
- http://www.google.com/foo
|
||||||
|
- http://www.google.com/bar
|
||||||
|
- http://www.google.com/baz
|
||||||
|
|
||||||
|
a
|
||||||
|
|
||||||
|
- http://www.google.com/foo
|
||||||
|
|
||||||
|
- http://www.google.com/bar
|
||||||
|
|
||||||
|
- http://www.google.com/baz
|
|
@ -5,87 +5,109 @@ var bootstrap = require('../bootstrap.js'),
|
||||||
showdown = bootstrap.showdown,
|
showdown = bootstrap.showdown,
|
||||||
assertion = bootstrap.assertion,
|
assertion = bootstrap.assertion,
|
||||||
testsuite = bootstrap.getTestSuite('test/features/'),
|
testsuite = bootstrap.getTestSuite('test/features/'),
|
||||||
tableSuite = bootstrap.getTestSuite('test/features/tables/');
|
tableSuite = bootstrap.getTestSuite('test/features/tables/'),
|
||||||
|
simplifiedAutoLinkSuite = bootstrap.getTestSuite('test/features/simplifiedAutoLink/');
|
||||||
|
|
||||||
describe('makeHtml() features testsuite', function () {
|
describe('makeHtml() features testsuite', function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
for (var i = 0; i < testsuite.length; ++i) {
|
|
||||||
var converter;
|
|
||||||
if (testsuite[i].name === '#143.support-image-dimensions') {
|
|
||||||
converter = new showdown.Converter({parseImgDimensions: true});
|
|
||||||
} else if (testsuite[i].name === '#69.header-level-start') {
|
|
||||||
converter = new showdown.Converter({headerLevelStart: 3});
|
|
||||||
} else if (testsuite[i].name === '#164.1.simple-autolink' || testsuite[i].name === '#204.certain-links-with-at-and-dot-break-url') {
|
|
||||||
converter = new showdown.Converter({simplifiedAutoLink: true});
|
|
||||||
} else if (testsuite[i].name === '#164.2.disallow-underscore-emphasis-mid-word') {
|
|
||||||
converter = new showdown.Converter({literalMidWordUnderscores: true});
|
|
||||||
} else if (testsuite[i].name === '#164.3.strikethrough' || testsuite[i].name === '#214.escaped-markdown-chars-break-strikethrough') {
|
|
||||||
converter = new showdown.Converter({strikethrough: true});
|
|
||||||
} else if (testsuite[i].name === 'disable-gh-codeblocks') {
|
|
||||||
converter = new showdown.Converter({ghCodeBlocks: false});
|
|
||||||
} else if (testsuite[i].name === '#164.4.tasklists') {
|
|
||||||
converter = new showdown.Converter({tasklists: true});
|
|
||||||
} else if (testsuite[i].name === 'autolink-and-disallow-underscores') {
|
|
||||||
converter = new showdown.Converter({literalMidWordUnderscores: true, simplifiedAutoLink: true});
|
|
||||||
} else if (testsuite[i].name === '#198.literalMidWordUnderscores-changes-behavior-of-asterisk') {
|
|
||||||
converter = new showdown.Converter({literalMidWordUnderscores: true});
|
|
||||||
} else if (testsuite[i].name === '#259.es6-template-strings-indentation-issues') {
|
|
||||||
converter = new showdown.Converter({smartIndentationFix: true});
|
|
||||||
} else if (testsuite[i].name === '#284.simplifiedAutoLink-does-not-match-GFM-style') {
|
|
||||||
converter = new showdown.Converter({simplifiedAutoLink: true});
|
|
||||||
} else if (testsuite[i].name === 'disableForced4SpacesIndentedSublists') {
|
|
||||||
converter = new showdown.Converter({disableForced4SpacesIndentedSublists: true});
|
|
||||||
} else if (testsuite[i].name === '#206.treat-single-line-breaks-as-br') {
|
|
||||||
converter = new showdown.Converter({simpleLineBreaks: true});
|
|
||||||
} else if (testsuite[i].name === 'simpleLineBreaks2') {
|
|
||||||
converter = new showdown.Converter({simpleLineBreaks: true});
|
|
||||||
} else if (testsuite[i].name === '#316.new-simpleLineBreaks-option-breaks-lists') {
|
|
||||||
converter = new showdown.Converter({simpleLineBreaks: true});
|
|
||||||
} else if (testsuite[i].name === '#323.simpleLineBreaks-breaks-with-strong') {
|
|
||||||
converter = new showdown.Converter({simpleLineBreaks: true});
|
|
||||||
} else if (testsuite[i].name === '#318.simpleLineBreaks-does-not-work-with-chinese-characters') {
|
|
||||||
converter = new showdown.Converter({simpleLineBreaks: true});
|
|
||||||
} else if (testsuite[i].name === 'simpleLineBreaks-handle-html-pre') {
|
|
||||||
converter = new showdown.Converter({simpleLineBreaks: true});
|
|
||||||
} else if (testsuite[i].name === 'excludeTrailingPunctuationFromURLs-option') {
|
|
||||||
converter = new showdown.Converter({simplifiedAutoLink: true, excludeTrailingPunctuationFromURLs: true});
|
|
||||||
} else if (testsuite[i].name === 'requireSpaceBeforeHeadingText') {
|
|
||||||
converter = new showdown.Converter({requireSpaceBeforeHeadingText: true});
|
|
||||||
} else if (testsuite[i].name === '#320.github-compatible-generated-header-id') {
|
|
||||||
converter = new showdown.Converter({ghCompatibleHeaderId: true});
|
|
||||||
} else if (testsuite[i].name === 'ghMentions') {
|
|
||||||
converter = new showdown.Converter({ghMentions: true});
|
|
||||||
} else if (testsuite[i].name === 'disable-email-encoding') {
|
|
||||||
converter = new showdown.Converter({encodeEmails: false});
|
|
||||||
} else if (testsuite[i].name === '#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail') {
|
|
||||||
converter = new showdown.Converter({encodeEmails: false, simplifiedAutoLink: true});
|
|
||||||
} else if (testsuite[i].name === '#331.allow-escaping-of-tilde') {
|
|
||||||
converter = new showdown.Converter({strikethrough: true});
|
|
||||||
} else if (testsuite[i].name === 'prefixHeaderId-simple') {
|
|
||||||
converter = new showdown.Converter({prefixHeaderId: true});
|
|
||||||
} else if (testsuite[i].name === 'prefixHeaderId-string') {
|
|
||||||
converter = new showdown.Converter({prefixHeaderId: 'my-prefix-'});
|
|
||||||
} else if (testsuite[i].name === 'prefixHeaderId-string-and-ghCompatibleHeaderId') {
|
|
||||||
converter = new showdown.Converter({prefixHeaderId: 'my-prefix-', ghCompatibleHeaderId: true});
|
|
||||||
} else if (testsuite[i].name === 'prefixHeaderId-string-and-ghCompatibleHeaderId2') {
|
|
||||||
converter = new showdown.Converter({prefixHeaderId: 'my prefix ', ghCompatibleHeaderId: true});
|
|
||||||
} else {
|
|
||||||
converter = new showdown.Converter();
|
|
||||||
}
|
|
||||||
it(testsuite[i].name.replace(/-/g, ' '), assertion(testsuite[i], converter));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
describe('issues', function () {
|
||||||
|
for (var i = 0; i < testsuite.length; ++i) {
|
||||||
|
var converter;
|
||||||
|
if (testsuite[i].name === '#143.support-image-dimensions') {
|
||||||
|
converter = new showdown.Converter({parseImgDimensions: true});
|
||||||
|
} else if (testsuite[i].name === '#69.header-level-start') {
|
||||||
|
converter = new showdown.Converter({headerLevelStart: 3});
|
||||||
|
} else if (testsuite[i].name === '#164.1.simple-autolink' || testsuite[i].name === '#204.certain-links-with-at-and-dot-break-url') {
|
||||||
|
converter = new showdown.Converter({simplifiedAutoLink: true});
|
||||||
|
} else if (testsuite[i].name === '#164.2.disallow-underscore-emphasis-mid-word') {
|
||||||
|
converter = new showdown.Converter({literalMidWordUnderscores: true});
|
||||||
|
} else if (testsuite[i].name === '#164.3.strikethrough' || testsuite[i].name === '#214.escaped-markdown-chars-break-strikethrough') {
|
||||||
|
converter = new showdown.Converter({strikethrough: true});
|
||||||
|
} else if (testsuite[i].name === 'disable-gh-codeblocks') {
|
||||||
|
converter = new showdown.Converter({ghCodeBlocks: false});
|
||||||
|
} else if (testsuite[i].name === '#164.4.tasklists') {
|
||||||
|
converter = new showdown.Converter({tasklists: true});
|
||||||
|
} else if (testsuite[i].name === '#198.literalMidWordUnderscores-changes-behavior-of-asterisk') {
|
||||||
|
converter = new showdown.Converter({literalMidWordUnderscores: true});
|
||||||
|
} else if (testsuite[i].name === '#259.es6-template-strings-indentation-issues') {
|
||||||
|
converter = new showdown.Converter({smartIndentationFix: true});
|
||||||
|
} else if (testsuite[i].name === '#284.simplifiedAutoLink-does-not-match-GFM-style') {
|
||||||
|
converter = new showdown.Converter({simplifiedAutoLink: true});
|
||||||
|
} else if (testsuite[i].name === 'disableForced4SpacesIndentedSublists') {
|
||||||
|
converter = new showdown.Converter({disableForced4SpacesIndentedSublists: true});
|
||||||
|
} else if (testsuite[i].name === '#206.treat-single-line-breaks-as-br') {
|
||||||
|
converter = new showdown.Converter({simpleLineBreaks: true});
|
||||||
|
} else if (testsuite[i].name === 'simpleLineBreaks2') {
|
||||||
|
converter = new showdown.Converter({simpleLineBreaks: true});
|
||||||
|
} else if (testsuite[i].name === '#316.new-simpleLineBreaks-option-breaks-lists') {
|
||||||
|
converter = new showdown.Converter({simpleLineBreaks: true});
|
||||||
|
} else if (testsuite[i].name === '#323.simpleLineBreaks-breaks-with-strong') {
|
||||||
|
converter = new showdown.Converter({simpleLineBreaks: true});
|
||||||
|
} else if (testsuite[i].name === '#318.simpleLineBreaks-does-not-work-with-chinese-characters') {
|
||||||
|
converter = new showdown.Converter({simpleLineBreaks: true});
|
||||||
|
} else if (testsuite[i].name === 'simpleLineBreaks-handle-html-pre') {
|
||||||
|
converter = new showdown.Converter({simpleLineBreaks: true});
|
||||||
|
} else if (testsuite[i].name === 'excludeTrailingPunctuationFromURLs-option') {
|
||||||
|
converter = new showdown.Converter({simplifiedAutoLink: true, excludeTrailingPunctuationFromURLs: true});
|
||||||
|
} else if (testsuite[i].name === 'requireSpaceBeforeHeadingText') {
|
||||||
|
converter = new showdown.Converter({requireSpaceBeforeHeadingText: true});
|
||||||
|
} else if (testsuite[i].name === '#320.github-compatible-generated-header-id') {
|
||||||
|
converter = new showdown.Converter({ghCompatibleHeaderId: true});
|
||||||
|
} else if (testsuite[i].name === 'ghMentions') {
|
||||||
|
converter = new showdown.Converter({ghMentions: true});
|
||||||
|
} else if (testsuite[i].name === 'disable-email-encoding') {
|
||||||
|
converter = new showdown.Converter({encodeEmails: false});
|
||||||
|
} else if (testsuite[i].name === '#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail') {
|
||||||
|
converter = new showdown.Converter({encodeEmails: false, simplifiedAutoLink: true});
|
||||||
|
} else if (testsuite[i].name === '#331.allow-escaping-of-tilde') {
|
||||||
|
converter = new showdown.Converter({strikethrough: true});
|
||||||
|
} else if (testsuite[i].name === 'prefixHeaderId-simple') {
|
||||||
|
converter = new showdown.Converter({prefixHeaderId: true});
|
||||||
|
} else if (testsuite[i].name === 'prefixHeaderId-string') {
|
||||||
|
converter = new showdown.Converter({prefixHeaderId: 'my-prefix-'});
|
||||||
|
} else if (testsuite[i].name === 'prefixHeaderId-string-and-ghCompatibleHeaderId') {
|
||||||
|
converter = new showdown.Converter({prefixHeaderId: 'my-prefix-', ghCompatibleHeaderId: true});
|
||||||
|
} else if (testsuite[i].name === 'prefixHeaderId-string-and-ghCompatibleHeaderId2') {
|
||||||
|
converter = new showdown.Converter({prefixHeaderId: 'my prefix ', ghCompatibleHeaderId: true});
|
||||||
|
} else if (testsuite[i].name === 'simplifiedAutoLink') {
|
||||||
|
converter = new showdown.Converter({simplifiedAutoLink: true, strikethrough: true});
|
||||||
|
} else {
|
||||||
|
converter = new showdown.Converter();
|
||||||
|
}
|
||||||
|
it(testsuite[i].name.replace(/-/g, ' '), assertion(testsuite[i], converter));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// test Table Syntax Support
|
||||||
describe('table support', function () {
|
describe('table support', function () {
|
||||||
var converter;
|
var converter,
|
||||||
for (var i = 0; i < tableSuite.length; ++i) {
|
suite = tableSuite;
|
||||||
if (tableSuite[i].name === 'basic-with-header-ids') {
|
for (var i = 0; i < suite.length; ++i) {
|
||||||
|
if (suite[i].name === 'basic-with-header-ids') {
|
||||||
converter = new showdown.Converter({tables: true, tableHeaderId: true});
|
converter = new showdown.Converter({tables: true, tableHeaderId: true});
|
||||||
} else if (tableSuite[i].name === '#179.parse-md-in-table-ths') {
|
} else if (suite[i].name === '#179.parse-md-in-table-ths') {
|
||||||
converter = new showdown.Converter({tables: true, strikethrough: true});
|
converter = new showdown.Converter({tables: true, strikethrough: true});
|
||||||
} else {
|
} else {
|
||||||
converter = new showdown.Converter({tables: true});
|
converter = new showdown.Converter({tables: true});
|
||||||
}
|
}
|
||||||
it(tableSuite[i].name.replace(/-/g, ' '), assertion(tableSuite[i], converter));
|
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// test simplifiedAutoLink Support
|
||||||
|
describe('simplifiedAutoLink support in', function () {
|
||||||
|
var converter,
|
||||||
|
suite = simplifiedAutoLinkSuite;
|
||||||
|
for (var i = 0; i < suite.length; ++i) {
|
||||||
|
if (suite[i].name === 'emphasis-and-strikethrough') {
|
||||||
|
converter = new showdown.Converter({simplifiedAutoLink: true, strikethrough: true});
|
||||||
|
} else if (suite[i].name === 'disallow-underscores') {
|
||||||
|
converter = new showdown.Converter({literalMidWordUnderscores: true, simplifiedAutoLink: true});
|
||||||
|
} else {
|
||||||
|
converter = new showdown.Converter({simplifiedAutoLink: true});
|
||||||
|
}
|
||||||
|
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user