Fixed all jshint warnings in showdown source.

closes #80
- Fixed tabbing of showdown source
- Added proper comparison operators
- Added missing semicolons
This commit is contained in:
nicovalencia 2014-01-08 13:38:22 -07:00
parent 10f461aa38
commit 7cd4829f9c

View File

@ -95,29 +95,29 @@ var stdExtName = function(s) {
//
Showdown.converter = function(converter_options) {
//
// Globals:
//
//
// Globals:
//
// Global hashes, used by various utility routines
var g_urls;
var g_titles;
var g_html_blocks;
// Global hashes, used by various utility routines
var g_urls;
var g_titles;
var g_html_blocks;
// Used to track when we're inside an ordered or unordered list
// (see _ProcessListItems() for details):
var g_list_level = 0;
// Used to track when we're inside an ordered or unordered list
// (see _ProcessListItems() for details):
var g_list_level = 0;
// Global extensions
var g_lang_extensions = [];
var g_output_modifiers = [];
// Global extensions
var g_lang_extensions = [];
var g_output_modifiers = [];
//
// Automatic Extension Loading (node only):
//
//
// Automatic Extension Loading (node only):
//
if (typeof module !== 'undefind' && typeof exports !== 'undefined' && typeof require !== 'undefind') {
if (typeof module !== 'undefined' && typeof exports !== 'undefined' && typeof require !== 'undefined') {
var fs = require('fs');
if (fs) {
@ -133,15 +133,15 @@ if (typeof module !== 'undefind' && typeof exports !== 'undefined' && typeof req
Showdown.extensions[name] = require('./extensions/' + ext);
});
}
}
}
this.makeHtml = function(text) {
//
// Main function. The order in which other subs are called here is
// essential. Link and image substitutions need to happen before
// _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the <a>
// and <img> tags get encoded.
//
this.makeHtml = function(text) {
//
// Main function. The order in which other subs are called here is
// essential. Link and image substitutions need to happen before
// _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the <a>
// and <img> tags get encoded.
//
// Clear the global hashes. If we don't clear these, you get conflicts
// from other articles when generating a page which contains more than
@ -209,13 +209,13 @@ this.makeHtml = function(text) {
});
return text;
};
//
// Options:
//
};
//
// Options:
//
// Parse extensions options into separate arrays
if (converter_options && converter_options.extensions) {
// Parse extensions options into separate arrays
if (converter_options && converter_options.extensions) {
var self = this;
@ -246,23 +246,23 @@ if (converter_options && converter_options.extensions) {
throw "Extension '" + plugin + "' could not be loaded. It was either not found or is not a valid extension.";
}
});
}
}
var _ExecuteExtension = function(ext, text) {
var _ExecuteExtension = function(ext, text) {
if (ext.regex) {
var re = new RegExp(ext.regex, 'g');
return text.replace(re, ext.replace);
} else if (ext.filter) {
return ext.filter(text);
}
};
};
var _StripLinkDefinitions = function(text) {
//
// Strips link definitions from text, stores the URLs and titles in
// hash references.
//
var _StripLinkDefinitions = function(text) {
//
// Strips link definitions from text, stores the URLs and titles in
// hash references.
//
// Link defs are in the form: ^[id]: url "optional title"
@ -312,10 +312,10 @@ var _StripLinkDefinitions = function(text) {
text = text.replace(/~0/,"");
return text;
}
};
var _HashHTMLBlocks = function(text) {
var _HashHTMLBlocks = function(text) {
// attacklab: Double up blank lines to reduce lookaround
text = text.replace(/\n/g,"\n\n");
@ -437,9 +437,9 @@ var _HashHTMLBlocks = function(text) {
// attacklab: Undo double lines (see comment at top of this function)
text = text.replace(/\n\n/g,"\n");
return text;
}
};
var hashElement = function(wholeMatch,m1) {
var hashElement = function(wholeMatch,m1) {
var blockText = m1;
// Undo double lines
@ -453,13 +453,13 @@ var hashElement = function(wholeMatch,m1) {
blockText = "\n\n~K" + (g_html_blocks.push(blockText)-1) + "K\n\n";
return blockText;
};
};
var _RunBlockGamut = function(text) {
//
// These are all the transformations that form block-level
// tags like paragraphs, headers, and list items.
//
var _RunBlockGamut = function(text) {
//
// These are all the transformations that form block-level
// tags like paragraphs, headers, and list items.
//
text = _DoHeaders(text);
// Do Horizontal Rules:
@ -480,14 +480,14 @@ var _RunBlockGamut = function(text) {
text = _FormParagraphs(text);
return text;
};
};
var _RunSpanGamut = function(text) {
//
// These are all the transformations that occur *within* block-level
// tags like paragraphs, headers, and list items.
//
var _RunSpanGamut = function(text) {
//
// These are all the transformations that occur *within* block-level
// tags like paragraphs, headers, and list items.
//
text = _DoCodeSpans(text);
text = _EscapeSpecialCharsWithinTagAttributes(text);
@ -509,13 +509,13 @@ var _RunSpanGamut = function(text) {
text = text.replace(/ +\n/g," <br />\n");
return text;
}
};
var _EscapeSpecialCharsWithinTagAttributes = function(text) {
//
// Within tags -- meaning between < and > -- encode [\ ` * _] so they
// don't conflict with their use in Markdown for code, italics and strong.
//
var _EscapeSpecialCharsWithinTagAttributes = function(text) {
//
// Within tags -- meaning between < and > -- encode [\ ` * _] so they
// don't conflict with their use in Markdown for code, italics and strong.
//
// Build a regex to find HTML tags and comments. See Friedl's
// "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
@ -528,12 +528,12 @@ var _EscapeSpecialCharsWithinTagAttributes = function(text) {
});
return text;
}
};
var _DoAnchors = function(text) {
//
// Turn Markdown link shortcuts into XHTML <a> tags.
//
var _DoAnchors = function(text) {
//
// Turn Markdown link shortcuts into XHTML <a> tags.
//
//
// First, handle reference-style links: [link text] [id]
//
@ -613,26 +613,26 @@ var _DoAnchors = function(text) {
text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);
return text;
}
};
var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
if (m7 == undefined) m7 = "";
var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
if (m7 === undefined) m7 = "";
var whole_match = m1;
var link_text = m2;
var link_id = m3.toLowerCase();
var url = m4;
var title = m7;
if (url == "") {
if (link_id == "") {
if (url === "") {
if (link_id === "") {
// lower-case and turn embedded newlines into spaces
link_id = link_text.toLowerCase().replace(/ ?\n/g," ");
}
url = "#"+link_id;
if (g_urls[link_id] != undefined) {
if (g_urls[link_id] !== undefined) {
url = g_urls[link_id];
if (g_titles[link_id] != undefined) {
if (g_titles[link_id] !== undefined) {
title = g_titles[link_id];
}
}
@ -649,7 +649,7 @@ var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
url = escapeCharacters(url,"*_");
var result = "<a href=\"" + url + "\"";
if (title != "") {
if (title !== "") {
title = title.replace(/"/g,"&quot;");
title = escapeCharacters(title,"*_");
result += " title=\"" + title + "\"";
@ -658,13 +658,13 @@ var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
result += ">" + link_text + "</a>";
return result;
}
};
var _DoImages = function(text) {
//
// Turn Markdown image shortcuts into <img> tags.
//
var _DoImages = function(text) {
//
// Turn Markdown image shortcuts into <img> tags.
//
//
// First, handle reference-style labeled images: ![alt text][id]
@ -717,9 +717,9 @@ var _DoImages = function(text) {
text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeImageTag);
return text;
}
};
var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
var whole_match = m1;
var alt_text = m2;
var link_id = m3.toLowerCase();
@ -728,16 +728,16 @@ var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
if (!title) title = "";
if (url == "") {
if (link_id == "") {
if (url === "") {
if (link_id === "") {
// lower-case and turn embedded newlines into spaces
link_id = alt_text.toLowerCase().replace(/ ?\n/g," ");
}
url = "#"+link_id;
if (g_urls[link_id] != undefined) {
if (g_urls[link_id] !== undefined) {
url = g_urls[link_id];
if (g_titles[link_id] != undefined) {
if (g_titles[link_id] !== undefined) {
title = g_titles[link_id];
}
}
@ -762,10 +762,10 @@ var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
result += " />";
return result;
}
};
var _DoHeaders = function(text) {
var _DoHeaders = function(text) {
// Setext-style headers:
// Header 1
@ -809,15 +809,15 @@ var _DoHeaders = function(text) {
return m.replace(/[^\w]/g, '').toLowerCase();
}
return text;
}
};
// This declaration keeps Dojo compressor from outputting garbage:
var _ProcessListItems;
// This declaration keeps Dojo compressor from outputting garbage:
var _ProcessListItems;
var _DoLists = function(text) {
//
// Form HTML ordered (numbered) and unordered (bulleted) lists.
//
var _DoLists = function(text) {
//
// Form HTML ordered (numbered) and unordered (bulleted) lists.
//
// attacklab: add sentinel to hack around khtml/safari bug:
// http://bugs.webkit.org/show_bug.cgi?id=11231
@ -855,7 +855,7 @@ var _DoLists = function(text) {
// Turn double returns into triple returns, so that we can make a
// paragraph for the last item in a list, if necessary:
list = list.replace(/\n{2,}/g,"\n\n\n");;
list = list.replace(/\n{2,}/g,"\n\n\n");
var result = _ProcessListItems(list);
// Trim any trailing whitespace, to put the closing `</$list_type>`
@ -875,7 +875,7 @@ var _DoLists = function(text) {
var list_type = (m3.search(/[*+-]/g)>-1) ? "ul" : "ol";
// Turn double returns into triple returns, so that we can make a
// paragraph for the last item in a list, if necessary:
var list = list.replace(/\n{2,}/g,"\n\n\n");;
list = list.replace(/\n{2,}/g,"\n\n\n");
var result = _ProcessListItems(list);
result = runup + "<"+list_type+">\n" + result + "</"+list_type+">\n";
return result;
@ -886,13 +886,13 @@ var _DoLists = function(text) {
text = text.replace(/~0/,"");
return text;
}
};
_ProcessListItems = function(list_str) {
//
// Process the contents of a single ordered or unordered list, splitting it
// into individual list items.
//
_ProcessListItems = function(list_str) {
//
// Process the contents of a single ordered or unordered list, splitting it
// into individual list items.
//
// The $g_list_level global keeps track of when we're inside a list.
// Each time we enter a list, we increment it; when we leave a list,
// we decrement. If it's zero, we're not in a list anymore.
@ -957,13 +957,13 @@ _ProcessListItems = function(list_str) {
g_list_level--;
return list_str;
}
};
var _DoCodeBlocks = function(text) {
//
// Process Markdown `<pre><code>` blocks.
//
var _DoCodeBlocks = function(text) {
//
// Process Markdown `<pre><code>` blocks.
//
/*
text = text.replace(text,
@ -1001,18 +1001,18 @@ var _DoCodeBlocks = function(text) {
text = text.replace(/~0/,"");
return text;
};
};
var _DoGithubCodeBlocks = function(text) {
//
// Process Github-style code blocks
// Example:
// ```ruby
// def hello_world(x)
// puts "Hello, #{x}"
// end
// ```
//
var _DoGithubCodeBlocks = function(text) {
//
// Process Github-style code blocks
// Example:
// ```ruby
// def hello_world(x)
// puts "Hello, #{x}"
// end
// ```
//
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
@ -1038,38 +1038,38 @@ var _DoGithubCodeBlocks = function(text) {
text = text.replace(/~0/,"");
return text;
}
};
var hashBlock = function(text) {
var hashBlock = function(text) {
text = text.replace(/(^\n+|\n+$)/g,"");
return "\n\n~K" + (g_html_blocks.push(text)-1) + "K\n\n";
}
};
var _DoCodeSpans = function(text) {
//
// * Backtick quotes are used for <code></code> spans.
//
// * You can use multiple backticks as the delimiters if you want to
// include literal backticks in the code span. So, this input:
//
// Just type ``foo `bar` baz`` at the prompt.
//
// Will translate to:
//
// <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
//
// There's no arbitrary limit to the number of backticks you
// can use as delimters. If you need three consecutive backticks
// in your code, use four for delimiters, etc.
//
// * You can use spaces to get literal backticks at the edges:
//
// ... type `` `bar` `` ...
//
// Turns to:
//
// ... type <code>`bar`</code> ...
//
var _DoCodeSpans = function(text) {
//
// * Backtick quotes are used for <code></code> spans.
//
// * You can use multiple backticks as the delimiters if you want to
// include literal backticks in the code span. So, this input:
//
// Just type ``foo `bar` baz`` at the prompt.
//
// Will translate to:
//
// <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
//
// There's no arbitrary limit to the number of backticks you
// can use as delimters. If you need three consecutive backticks
// in your code, use four for delimiters, etc.
//
// * You can use spaces to get literal backticks at the edges:
//
// ... type `` `bar` `` ...
//
// Turns to:
//
// ... type <code>`bar`</code> ...
//
/*
text = text.replace(/
@ -1094,14 +1094,14 @@ var _DoCodeSpans = function(text) {
});
return text;
}
};
var _EncodeCode = function(text) {
//
// Encode/escape certain characters inside Markdown code runs.
// The point is that in code, these characters are literals,
// and lose their special Markdown meanings.
//
var _EncodeCode = function(text) {
//
// Encode/escape certain characters inside Markdown code runs.
// The point is that in code, these characters are literals,
// and lose their special Markdown meanings.
//
// Encode all ampersands; HTML entities are not
// entities within a Markdown code span.
text = text.replace(/&/g,"&amp;");
@ -1111,23 +1111,23 @@ var _EncodeCode = function(text) {
text = text.replace(/>/g,"&gt;");
// Now, escape characters that are magic in Markdown:
text = escapeCharacters(text,"\*_{}[]\\",false);
text = escapeCharacters(text,"\\*_{}[]\\",false);
// jj the line above breaks this:
//---
// jj the line above breaks this:
//---
//* Item
//* Item
// 1. Subitem
// 1. Subitem
// special char: *
//---
// special char: *
//---
return text;
}
};
var _DoItalicsAndBold = function(text) {
var _DoItalicsAndBold = function(text) {
// <strong> must go first:
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,
@ -1137,10 +1137,10 @@ var _DoItalicsAndBold = function(text) {
"<em>$2</em>");
return text;
}
};
var _DoBlockQuotes = function(text) {
var _DoBlockQuotes = function(text) {
/*
text = text.replace(/
@ -1185,14 +1185,14 @@ var _DoBlockQuotes = function(text) {
return hashBlock("<blockquote>\n" + bq + "\n</blockquote>");
});
return text;
}
};
var _FormParagraphs = function(text) {
//
// Params:
// $text - string to process with html <p> tags
//
var _FormParagraphs = function(text) {
//
// Params:
// $text - string to process with html <p> tags
//
// Strip leading and trailing lines:
text = text.replace(/^\n+/g,"");
@ -1215,7 +1215,7 @@ var _FormParagraphs = function(text) {
else if (str.search(/\S/) >= 0) {
str = _RunSpanGamut(str);
str = str.replace(/^([ \t]*)/g,"<p>");
str += "</p>"
str += "</p>";
grafsOut.push(str);
}
@ -1225,21 +1225,21 @@ var _FormParagraphs = function(text) {
// Unhashify HTML blocks
//
end = grafsOut.length;
for (var i=0; i<end; i++) {
for (var j=0; j<end; j++) {
// if this is a marker for an html block...
while (grafsOut[i].search(/~K(\d+)K/) >= 0) {
while (grafsOut[j].search(/~K(\d+)K/) >= 0) {
var blockText = g_html_blocks[RegExp.$1];
blockText = blockText.replace(/\$/g,"$$$$"); // Escape any dollar signs
grafsOut[i] = grafsOut[i].replace(/~K\d+K/,blockText);
grafsOut[j] = grafsOut[j].replace(/~K\d+K/,blockText);
}
}
return grafsOut.join("\n\n");
}
};
var _EncodeAmpsAndAngles = function(text) {
// Smart processing for ampersands and angle brackets that need to be encoded.
var _EncodeAmpsAndAngles = function(text) {
// Smart processing for ampersands and angle brackets that need to be encoded.
// Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
// http://bumppo.net/projects/amputator/
@ -1249,15 +1249,15 @@ var _EncodeAmpsAndAngles = function(text) {
text = text.replace(/<(?![a-z\/?\$!])/gi,"&lt;");
return text;
}
};
var _EncodeBackslashEscapes = function(text) {
//
// Parameter: String.
// Returns: The string, with after processing the following backslash
// escape sequences.
//
var _EncodeBackslashEscapes = function(text) {
//
// Parameter: String.
// Returns: The string, with after processing the following backslash
// escape sequences.
//
// attacklab: The polite way to do this is with the new
// escapeCharacters() function:
@ -1271,10 +1271,10 @@ var _EncodeBackslashEscapes = function(text) {
text = text.replace(/\\(\\)/g,escapeCharacters_callback);
text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g,escapeCharacters_callback);
return text;
}
};
var _DoAutoLinks = function(text) {
var _DoAutoLinks = function(text) {
text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi,"<a href=\"$1\">$1</a>");
@ -1299,24 +1299,24 @@ var _DoAutoLinks = function(text) {
);
return text;
}
};
var _EncodeEmailAddress = function(addr) {
//
// Input: an email address, e.g. "foo@example.com"
//
// Output: the email address as a mailto link, with each character
// of the address encoded as either a decimal or hex entity, in
// the hopes of foiling most address harvesting spam bots. E.g.:
//
// <a href="&#x6D;&#97;&#105;&#108;&#x74;&#111;:&#102;&#111;&#111;&#64;&#101;
// x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;">&#102;&#111;&#111;
// &#64;&#101;x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;</a>
//
// Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
// mailing list: <http://tinyurl.com/yu7ue>
//
var _EncodeEmailAddress = function(addr) {
//
// Input: an email address, e.g. "foo@example.com"
//
// Output: the email address as a mailto link, with each character
// of the address encoded as either a decimal or hex entity, in
// the hopes of foiling most address harvesting spam bots. E.g.:
//
// <a href="&#x6D;&#97;&#105;&#108;&#x74;&#111;:&#102;&#111;&#111;&#64;&#101;
// x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;">&#102;&#111;&#111;
// &#64;&#101;x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;</a>
//
// Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
// mailing list: <http://tinyurl.com/yu7ue>
//
var encode = [
function(ch){return "&#"+ch.charCodeAt(0)+";";},
@ -1335,8 +1335,8 @@ var _EncodeEmailAddress = function(addr) {
var r = Math.random();
// roughly 10% raw, 45% hex, 45% dec
ch = (
r > .9 ? encode[2](ch) :
r > .45 ? encode[1](ch) :
r > 0.9 ? encode[2](ch) :
r > 0.45 ? encode[1](ch) :
encode[0](ch)
);
}
@ -1347,13 +1347,13 @@ var _EncodeEmailAddress = function(addr) {
addr = addr.replace(/">.+:/g,"\">"); // strip the mailto: from the visible part
return addr;
}
};
var _UnescapeSpecialChars = function(text) {
//
// Swap back in all the special characters we've hidden.
//
var _UnescapeSpecialChars = function(text) {
//
// Swap back in all the special characters we've hidden.
//
text = text.replace(/~E(\d+)E/g,
function(wholeMatch,m1) {
var charCodeToReplace = parseInt(m1);
@ -1361,13 +1361,13 @@ var _UnescapeSpecialChars = function(text) {
}
);
return text;
}
};
var _Outdent = function(text) {
//
// Remove one level of line-leading tabs or spaces
//
var _Outdent = function(text) {
//
// Remove one level of line-leading tabs or spaces
//
// attacklab: hack around Konqueror 3.5.4 bug:
// "----------bug".replace(/^-/g,"") == "bug"
@ -1375,15 +1375,15 @@ var _Outdent = function(text) {
text = text.replace(/^(\t|[ ]{1,4})/gm,"~0"); // attacklab: g_tab_width
// attacklab: clean up hack
text = text.replace(/~0/g,"")
text = text.replace(/~0/g,"");
return text;
}
};
var _Detab = function(text) {
// attacklab: Detab's completely rewritten for speed.
// In perl we could fix it by anchoring the regexp with \G.
// In javascript we're less fortunate.
var _Detab = function(text) {
// attacklab: Detab's completely rewritten for speed.
// In perl we could fix it by anchoring the regexp with \G.
// In javascript we're less fortunate.
// expand first n-1 tabs
text = text.replace(/\t(?=\t)/g," "); // attacklab: g_tab_width
@ -1409,15 +1409,15 @@ var _Detab = function(text) {
text = text.replace(/~B/g,"");
return text;
}
};
//
// attacklab: Utility functions
//
//
// attacklab: Utility functions
//
var escapeCharacters = function(text, charsToEscape, afterBackslash) {
var escapeCharacters = function(text, charsToEscape, afterBackslash) {
// First we have to escape the escape characters so that
// we can build a character class out of them
var regexString = "([" + charsToEscape.replace(/([\[\]\\])/g,"\\$1") + "])";
@ -1430,15 +1430,15 @@ var escapeCharacters = function(text, charsToEscape, afterBackslash) {
text = text.replace(regex,escapeCharacters_callback);
return text;
}
};
var escapeCharacters_callback = function(wholeMatch,m1) {
var escapeCharacters_callback = function(wholeMatch,m1) {
var charCodeToEscape = m1.charCodeAt(0);
return "~E"+charCodeToEscape+"E";
}
};
} // end of Showdown.converter
}; // end of Showdown.converter
// export