chore(): code style fix and tests fix due to code style changes

This commit is contained in:
Estevão Soares dos Santos 2015-01-19 12:04:22 +00:00
parent 29c108d5a5
commit 79829dbbf1
27 changed files with 81 additions and 78 deletions

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

7
src/angular.js vendored
View File

@ -9,9 +9,10 @@ if (typeof angular !== 'undefined' && typeof showdown !== 'undefined') {
(function (module, showdown) { (function (module, showdown) {
'use strict'; 'use strict';
module.provider('$showdown', provider).directive('sdModelToHtml', module
['$showdown', markdownToHtmlDirective]).filter('sdStripHtml', .provider('$showdown', provider)
stripHtmlFilter); .directive('sdModelToHtml',['$showdown', markdownToHtmlDirective])
.filter('sdStripHtml', stripHtmlFilter);
/** /**
* Angular Provider * Angular Provider

View File

@ -11,6 +11,7 @@ if (typeof module !== 'undefined' && module.exports) {
// AMD Loader // AMD Loader
else if (typeof define === 'function' && define.amd) { else if (typeof define === 'function' && define.amd) {
define('showdown', function () { define('showdown', function () {
'use strict';
return showdown; return showdown;
}); });
} }

View File

@ -5,7 +5,7 @@
showdown.subParser('autoLinks', function (text) { showdown.subParser('autoLinks', function (text) {
'use strict'; 'use strict';
text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi, "<a href=\"$1\">$1</a>"); text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi, '<a href=\"$1\">$1</a>');
// Email addresses: <address@domain.foo> // Email addresses: <address@domain.foo>
@ -19,9 +19,10 @@ showdown.subParser('autoLinks', function (text) {
[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+ [-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
) )
> >
/gi, _DoAutoLinks_callback()); /gi);
*/ */
text = text.replace(/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi, function (wholeMatch, m1) { var pattern = /<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
text = text.replace(pattern, function (wholeMatch, m1) {
var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1); var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1);
return showdown.subParser('encodeEmailAddress')(unescapedStr); return showdown.subParser('encodeEmailAddress')(unescapedStr);
}); });

View File

@ -24,20 +24,20 @@ showdown.subParser('codeBlocks', function (text, options, globals) {
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
text += '~0'; text += '~0';
text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g, var pattern = /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g;
function (wholeMatch, m1, m2) { text = text.replace(pattern, function (wholeMatch, m1, m2) {
var codeblock = m1, nextChar = m2; var codeblock = m1, nextChar = m2;
codeblock = showdown.subParser('outdent')(codeblock); codeblock = showdown.subParser('outdent')(codeblock);
codeblock = showdown.subParser('encodeCode')(codeblock); codeblock = showdown.subParser('encodeCode')(codeblock);
codeblock = showdown.subParser('detab')(codeblock); codeblock = showdown.subParser('detab')(codeblock);
codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace
codeblock = '<pre><code>' + codeblock + '\n</code></pre>'; codeblock = '<pre><code>' + codeblock + '\n</code></pre>';
return showdown.subParser('hashBlock')(codeblock, options, globals) + nextChar; return showdown.subParser('hashBlock')(codeblock, options, globals) + nextChar;
}); });
// attacklab: strip sentinel // attacklab: strip sentinel
text = text.replace(/~0/, ''); text = text.replace(/~0/, '');

View File

@ -16,7 +16,8 @@ showdown.subParser('detab', function (text) {
// use the sentinel to anchor our regex so it doesn't explode // use the sentinel to anchor our regex so it doesn't explode
text = text.replace(/~B(.+?)~A/g, function (wholeMatch, m1) { text = text.replace(/~B(.+?)~A/g, function (wholeMatch, m1) {
var leadingText = m1, numSpaces = 4 - leadingText.length % 4; // g_tab_width var leadingText = m1,
numSpaces = 4 - leadingText.length % 4; // g_tab_width
// there *must* be a better way to do this: // there *must* be a better way to do this:
for (var i = 0; i < numSpaces; i++) { for (var i = 0; i < numSpaces; i++) {

View File

@ -29,5 +29,4 @@ showdown.subParser('encodeCode', function (text) {
// --- // ---
return text; return text;
}); });

View File

@ -23,9 +23,11 @@ showdown.subParser('encodeEmailAddress', function (addr) {
var encode = [ var encode = [
function (ch) { function (ch) {
return '&#' + ch.charCodeAt(0) + ';'; return '&#' + ch.charCodeAt(0) + ';';
}, function (ch) { },
function (ch) {
return '&#x' + ch.charCodeAt(0).toString(16) + ';'; return '&#x' + ch.charCodeAt(0).toString(16) + ';';
}, function (ch) { },
function (ch) {
return ch; return ch;
} }
]; ];
@ -51,5 +53,4 @@ showdown.subParser('encodeEmailAddress', function (addr) {
addr = addr.replace(/">.+:/g, '">'); // strip the mailto: from the visible part addr = addr.replace(/">.+:/g, '">'); // strip the mailto: from the visible part
return addr; return addr;
}); });

View File

@ -18,7 +18,9 @@ showdown.subParser('githubCodeBlocks', function (text, options, globals) {
text += '~0'; text += '~0';
text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, m1, m2) { text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, m1, m2) {
var language = m1, codeblock = m2, end = '\n'; var language = m1,
codeblock = m2,
end = '\n';
if (options.omitExtraWLInCodeBlocks) { if (options.omitExtraWLInCodeBlocks) {
end = ''; end = '';

View File

@ -15,17 +15,15 @@ showdown.subParser('headers', function (text, options, globals) {
// -------- // --------
// //
text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm, function (wholeMatch, m1) { text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm, function (wholeMatch, m1) {
return showdown.subParser('hashBlock')('<h1 id="' + headerId(m1) + '">' + showdown.subParser('spanGamut')(m1, var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
options, hashBlock = '<h1 id="' + headerId(m1) + '">' + spanGamut + '</h1>';
globals) + '</h1>', return showdown.subParser('hashBlock')(hashBlock, options, globals);
options, globals);
}); });
text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm, function (matchFound, m1) { text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm, function (matchFound, m1) {
return showdown.subParser('hashBlock')('<h2 id="' + headerId(m1) + '">' + showdown.subParser('spanGamut')(m1, var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
options, hashBlock = '<h2 id="' + headerId(m1) + '">' + spanGamut + '</h2>';
globals) + '</h2>', return showdown.subParser('hashBlock')(hashBlock, options, globals);
options, globals);
}); });
// atx-style headers: // atx-style headers:
@ -48,8 +46,8 @@ showdown.subParser('headers', function (text, options, globals) {
*/ */
text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm, function (wholeMatch, m1, m2) { text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm, function (wholeMatch, m1, m2) {
var span = showdown.subParser('spanGamut')(m2, options, var span = showdown.subParser('spanGamut')(m2, options, globals),
globals), header = '<h' + m1.length + ' id="' + headerId(m2) + '">' + span + '</h' + m1.length + '>'; header = '<h' + m1.length + ' id="' + headerId(m2) + '">' + span + '</h' + m1.length + '>';
return showdown.subParser('hashBlock')(header, options, globals); return showdown.subParser('hashBlock')(header, options, globals);
}); });

View File

@ -11,7 +11,12 @@ showdown.subParser('images', function (text, options, globals) {
var writeImageTag = function (wholeMatch, m1, m2, m3, m4, m5, m6, m7) { var writeImageTag = function (wholeMatch, m1, m2, m3, m4, m5, m6, m7) {
wholeMatch = m1; wholeMatch = m1;
var altText = m2, linkId = m3.toLowerCase(), url = m4, title = m7, gUrls = globals.gUrls, gTitles = globals.gTitles; var altText = m2,
linkId = m3.toLowerCase(),
url = m4,
title = m7,
gUrls = globals.gUrls,
gTitles = globals.gTitles;
if (!title) { if (!title) {
title = ''; title = '';

View File

@ -109,7 +109,8 @@ showdown.subParser('lists', function (text, options, globals) {
if (globals.gListLevel) { if (globals.gListLevel) {
text = text.replace(wholeList, function (wholeMatch, m1, m2) { text = text.replace(wholeList, function (wholeMatch, m1, m2) {
var list = m1, listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol'; var list = m1,
listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
// Turn double returns into triple returns, so that we can make a // Turn double returns into triple returns, so that we can make a
// paragraph for the last item in a list, if necessary: // paragraph for the last item in a list, if necessary:
@ -132,8 +133,9 @@ showdown.subParser('lists', function (text, options, globals) {
// Turn double returns into triple returns, so that we can make a // Turn double returns into triple returns, so that we can make a
// paragraph for the last item in a list, if necessary: // paragraph for the last item in a list, if necessary:
var list = m2.replace(/\n{2,}/g, var list = m2.replace(/\n{2,}/g, '\n\n\n'),
'\n\n\n'), listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol', result = processListItems(list); listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol',
result = processListItems(list);
return m1 + '<' + listType + '>\n' + result + '</' + listType + '>\n'; return m1 + '<' + listType + '>\n' + result + '</' + listType + '>\n';
}); });

View File

@ -30,25 +30,26 @@
showdown.subParser('stripLinkDefinitions', function (text, options, globals) { showdown.subParser('stripLinkDefinitions', function (text, options, globals) {
'use strict'; 'use strict';
var regex = /^[ ]{0,3}\[(.+)]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|(?=~0))/gm;
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
text += '~0'; text += '~0';
text = text.replace(/^[ ]{0,3}\[(.+)]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|(?=~0))/gm, text = text.replace(regex, function (wholeMatch, m1, m2, m3, m4) {
function (wholeMatch, m1, m2, m3, m4) { m1 = m1.toLowerCase();
m1 = m1.toLowerCase(); globals.gUrls[m1] = showdown.subParser('encodeAmpsAndAngles')(m2); // Link IDs are case-insensitive
globals.gUrls[m1] = showdown.subParser('encodeAmpsAndAngles')(m2); // Link IDs are if (m3) {
// case-insensitive // Oops, found blank lines, so it's not a title.
if (m3) { // Put back the parenthetical statement we stole.
// Oops, found blank lines, so it's not a title. return m3 + m4;
// Put back the parenthetical statement we stole.
return m3 + m4;
} else if (m4) {
globals.gTitles[m1] = m4.replace(/"/g, '&quot;');
}
// Completely remove the definition from the text } else if (m4) {
return ''; globals.gTitles[m1] = m4.replace(/"/g, '&quot;');
}); }
// Completely remove the definition from the text
return '';
});
// attacklab: strip sentinel // attacklab: strip sentinel
text = text.replace(/~0/, ''); text = text.replace(/~0/, '');

View File

@ -1 +1 @@
It happened in 1986\. What a great season. It happened in 1986\. What a great season.

View File

@ -1,9 +1,9 @@
<hr/> <hr />
<hr/> <hr />
<hr/> <hr />
<hr/> <hr />
<hr/> <hr />

View File

@ -13,8 +13,7 @@
<aside>ignore me</aside> <aside>ignore me</aside>
<article>read <article>read
me me</article>
</article>
<aside> <aside>
ignore me ignore me

View File

@ -1,5 +1,5 @@
<p><img src="/path/to/img.jpg" alt="Alt text" title=""/></p> <p><img src="/path/to/img.jpg" alt="Alt text" title="" /></p>
<p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p> <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title" /></p>
<p><img src="url/to/image" alt="Alt text" title="Optional title attribute"/></p> <p><img src="url/to/image" alt="Alt text" title="Optional title attribute" /></p>

View File

@ -1,2 +1 @@
<p>Search the web at <a href="http://google.com/">Google</a> or <a href="http://daringfireball.net/">Daring Fireball</a>. <p>Search the web at <a href="http://google.com/">Google</a> or <a href="http://daringfireball.net/">Daring Fireball</a>.</p>
</p>

View File

@ -1,7 +1,5 @@
<style> <style>
p { p { line-height: 20px; }
line-height: 20px;
}
</style> </style>
<p>An exciting sentence.</p> <p>An exciting sentence.</p>

View File

@ -4,6 +4,5 @@
<blockquote> <blockquote>
<p>This is a blockquote <p>This is a blockquote
inside a list item.</p> inside a list item.</p>
</blockquote> </blockquote></li>
</li>
</ul> </ul>

View File

@ -2,6 +2,5 @@
<li><p>A list item with code:</p> <li><p>A list item with code:</p>
<pre><code>alert('Hello world!'); <pre><code>alert('Hello world!');
</code></pre> </code></pre></li>
</li>
</ul> </ul>

View File

@ -1,6 +1,5 @@
<ul> <ul>
<li>This line spans <li>This line spans
more than one line and is lazy more than one line and is lazy</li>
</li>
<li>Similar to this line</li> <li>Similar to this line</li>
</ul> </ul>

View File

@ -1,2 +1 @@
<p>There's an <a href="http://en.memory-alpha.org/wiki/Darmok_(episode)">episode</a> of Star Trek: The Next Generation <p>There's an <a href="http://en.memory-alpha.org/wiki/Darmok_(episode)">episode</a> of Star Trek: The Next Generation</p>
</p>

View File

@ -1,2 +1 @@
There's an [episode](http://en.memory-alpha.org/wiki/Darmok_(episode)) of Star Trek: The Next Generation
There's an [episode](http://en.memory-alpha.org/wiki/Darmok_(episode)) of Star Trek: The Next Generation