|
@@ -191,7 +191,7 @@ var _StripLinkDefinitions = function(text) {
|
|
|
} else if (m4) {
|
|
|
g_titles[m1] = m4.replace(/"/g,""");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Completely remove the definition from the text
|
|
|
return "";
|
|
|
}
|
|
@@ -264,7 +264,7 @@ var _HashHTMLBlocks = function(text) {
|
|
|
text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\b[^\r]*?.*<\/\2>[ \t]*(?=\n+)\n)/gm,hashElement);
|
|
|
|
|
|
// Special case just for <hr />. It was easier to make a special case than
|
|
|
- // to make the other regex more complicated.
|
|
|
+ // to make the other regex more complicated.
|
|
|
|
|
|
/*
|
|
|
text = text.replace(/
|
|
@@ -273,7 +273,7 @@ var _HashHTMLBlocks = function(text) {
|
|
|
[ ]{0,3}
|
|
|
(<(hr) // start tag = $2
|
|
|
\b // word break
|
|
|
- ([^<>])*? //
|
|
|
+ ([^<>])*? //
|
|
|
\/?>) // the matching end tag
|
|
|
[ \t]*
|
|
|
(?=\n{2,}) // followed by a blank line
|
|
@@ -331,13 +331,13 @@ var hashElement = function(wholeMatch,m1) {
|
|
|
// Undo double lines
|
|
|
blockText = blockText.replace(/\n\n/g,"\n");
|
|
|
blockText = blockText.replace(/^\n/,"");
|
|
|
-
|
|
|
+
|
|
|
// strip trailing blank lines
|
|
|
blockText = blockText.replace(/\n+$/g,"");
|
|
|
-
|
|
|
+
|
|
|
// Replace the element text with a marker ("~KxK" where x is its key)
|
|
|
blockText = "\n\n~K" + (g_html_blocks.push(blockText)-1) + "K\n\n";
|
|
|
-
|
|
|
+
|
|
|
return blockText;
|
|
|
};
|
|
|
|
|
@@ -404,7 +404,7 @@ var _EscapeSpecialCharsWithinTagAttributes = function(text) {
|
|
|
// 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.
|
|
|
var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi;
|
|
|
|
|
@@ -509,14 +509,14 @@ var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
|
|
|
var link_id = m3.toLowerCase();
|
|
|
var url = m4;
|
|
|
var title = m7;
|
|
|
-
|
|
|
+
|
|
|
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) {
|
|
|
url = g_urls[link_id];
|
|
|
if (g_titles[link_id] != undefined) {
|
|
@@ -531,19 +531,19 @@ var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
|
|
|
return whole_match;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
url = escapeCharacters(url,"*_");
|
|
|
var result = "<a href=\"" + url + "\"";
|
|
|
-
|
|
|
+
|
|
|
if (title != "") {
|
|
|
title = title.replace(/"/g,""");
|
|
|
title = escapeCharacters(title,"*_");
|
|
|
result += " title=\"" + title + "\"";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
result += ">" + link_text + "</a>";
|
|
|
-
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -614,14 +614,14 @@ var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
|
|
|
var title = m7;
|
|
|
|
|
|
if (!title) title = "";
|
|
|
-
|
|
|
+
|
|
|
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) {
|
|
|
url = g_urls[link_id];
|
|
|
if (g_titles[link_id] != undefined) {
|
|
@@ -631,8 +631,8 @@ var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
|
|
|
else {
|
|
|
return whole_match;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
alt_text = alt_text.replace(/"/g,""");
|
|
|
url = escapeCharacters(url,"*_");
|
|
|
var result = "<img src=\"" + url + "\" alt=\"" + alt_text + "\"";
|
|
@@ -645,9 +645,9 @@ var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
|
|
|
title = escapeCharacters(title,"*_");
|
|
|
result += " title=\"" + title + "\"";
|
|
|
//}
|
|
|
-
|
|
|
+
|
|
|
result += " />";
|
|
|
-
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -657,7 +657,7 @@ var _DoHeaders = function(text) {
|
|
|
// Setext-style headers:
|
|
|
// Header 1
|
|
|
// ========
|
|
|
- //
|
|
|
+ //
|
|
|
// Header 2
|
|
|
// --------
|
|
|
//
|
|
@@ -744,7 +744,7 @@ var _DoLists = function(text) {
|
|
|
// paragraph for the last item in a list, if necessary:
|
|
|
list = list.replace(/\n{2,}/g,"\n\n\n");;
|
|
|
var result = _ProcessListItems(list);
|
|
|
-
|
|
|
+
|
|
|
// Trim any trailing whitespace, to put the closing `</$list_type>`
|
|
|
// up on the preceding line, to get it past the current stupid
|
|
|
// HTML block parser. This is a hack to work around the terrible
|
|
@@ -764,7 +764,7 @@ var _DoLists = function(text) {
|
|
|
// paragraph for the last item in a list, if necessary:
|
|
|
var list = list.replace(/\n{2,}/g,"\n\n\n");;
|
|
|
var result = _ProcessListItems(list);
|
|
|
- result = runup + "<"+list_type+">\n" + result + "</"+list_type+">\n";
|
|
|
+ result = runup + "<"+list_type+">\n" + result + "</"+list_type+">\n";
|
|
|
return result;
|
|
|
});
|
|
|
}
|
|
@@ -850,7 +850,7 @@ _ProcessListItems = function(list_str) {
|
|
|
var _DoCodeBlocks = function(text) {
|
|
|
//
|
|
|
// Process Markdown `<pre><code>` blocks.
|
|
|
-//
|
|
|
+//
|
|
|
|
|
|
/*
|
|
|
text = text.replace(text,
|
|
@@ -867,12 +867,12 @@ var _DoCodeBlocks = function(text) {
|
|
|
|
|
|
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
|
|
|
text += "~0";
|
|
|
-
|
|
|
+
|
|
|
text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,
|
|
|
function(wholeMatch,m1,m2) {
|
|
|
var codeblock = m1;
|
|
|
var nextChar = m2;
|
|
|
-
|
|
|
+
|
|
|
codeblock = _EncodeCode( _Outdent(codeblock));
|
|
|
codeblock = _Detab(codeblock);
|
|
|
codeblock = codeblock.replace(/^\n+/g,""); // trim leading newlines
|
|
@@ -899,23 +899,23 @@ var _DoGithubCodeBlocks = function(text) {
|
|
|
// puts "Hello, #{x}"
|
|
|
// end
|
|
|
// ```
|
|
|
-//
|
|
|
+//
|
|
|
|
|
|
|
|
|
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
|
|
|
text += "~0";
|
|
|
-
|
|
|
+
|
|
|
text = text.replace(/\n```(.*)\n([^`]+)\n```/g,
|
|
|
function(wholeMatch,m1,m2) {
|
|
|
var language = m1;
|
|
|
var codeblock = m2;
|
|
|
-
|
|
|
+
|
|
|
codeblock = _EncodeCode(codeblock);
|
|
|
codeblock = _Detab(codeblock);
|
|
|
codeblock = codeblock.replace(/^\n+/g,""); // trim leading newlines
|
|
|
codeblock = codeblock.replace(/\n+$/g,""); // trim trailing whitespace
|
|
|
|
|
|
- codeblock = "<pre><code class=" + language + ">" + codeblock + "\n</code></pre>";
|
|
|
+ codeblock = "<pre><code" + (language ? " class=" + language : "") + ">" + codeblock + "\n</code></pre>";
|
|
|
|
|
|
return hashBlock(codeblock);
|
|
|
}
|
|
@@ -935,26 +935,26 @@ var hashBlock = function(text) {
|
|
|
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> ...
|
|
|
//
|
|
|
|
|
@@ -1056,7 +1056,7 @@ var _DoBlockQuotes = function(text) {
|
|
|
|
|
|
bq = bq.replace(/^[ \t]+$/gm,""); // trim whitespace-only lines
|
|
|
bq = _RunBlockGamut(bq); // recurse
|
|
|
-
|
|
|
+
|
|
|
bq = bq.replace(/(^|\n)/g,"$1 ");
|
|
|
// These leading spaces screw with <pre> content, so we need to fix that:
|
|
|
bq = bq.replace(
|
|
@@ -1068,7 +1068,7 @@ var _DoBlockQuotes = function(text) {
|
|
|
pre = pre.replace(/~0/g,"");
|
|
|
return pre;
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
return hashBlock("<blockquote>\n" + bq + "\n</blockquote>");
|
|
|
});
|
|
|
return text;
|
|
@@ -1127,14 +1127,14 @@ var _FormParagraphs = function(text) {
|
|
|
|
|
|
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/
|
|
|
text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g,"&");
|
|
|
-
|
|
|
+
|
|
|
// Encode naked <'s
|
|
|
text = text.replace(/<(?![a-z\/?\$!])/gi,"<");
|
|
|
-
|
|
|
+
|
|
|
return text;
|
|
|
}
|
|
|
|