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