mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
refactor(event dispatcher): make event dispatcher return an object instead of text
This commit is contained in:
parent
e80a548c9b
commit
05ef5c55dc
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.
|
@ -197,7 +197,7 @@ showdown.Converter = function (converterOptions) {
|
|||
if (typeof callback !== 'function') {
|
||||
throw Error('Invalid argument in converter.listen() method: callback must be a function, but ' + typeof callback + ' given');
|
||||
}
|
||||
|
||||
name = name.toLowerCase();
|
||||
if (!listeners.hasOwnProperty(name)) {
|
||||
listeners[name] = [];
|
||||
}
|
||||
|
@ -211,24 +211,33 @@ showdown.Converter = function (converterOptions) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Dispatch an event
|
||||
* @private
|
||||
*
|
||||
* @param {string} evtName Event name
|
||||
* @param {string} text Text
|
||||
* @param {{}} options Converter Options
|
||||
* @param {{}} globals
|
||||
* @returns {string}
|
||||
* @param {{}} globals Converter globals
|
||||
* @param {{}} pParams extra params for event
|
||||
* @returns showdown.helper.Event
|
||||
* @private
|
||||
*/
|
||||
this._dispatch = function dispatch (evtName, text, options, globals) {
|
||||
this._dispatch = function dispatch (evtName, text, options, globals, pParams) {
|
||||
evtName = evtName.toLowerCase();
|
||||
var params = pParams || {};
|
||||
params.converter = this;
|
||||
params.text = text;
|
||||
params.options = options;
|
||||
params.globals = globals;
|
||||
var event = new showdown.helper.Event(evtName, text, params);
|
||||
|
||||
if (listeners.hasOwnProperty(evtName)) {
|
||||
for (var ei = 0; ei < listeners[evtName].length; ++ei) {
|
||||
var nText = listeners[evtName][ei](evtName, text, this, options, globals);
|
||||
var nText = listeners[evtName][ei](event);
|
||||
if (nText && typeof nText !== 'undefined') {
|
||||
text = nText;
|
||||
event.setText(nText);
|
||||
}
|
||||
}
|
||||
}
|
||||
return text;
|
||||
return event;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,74 +4,96 @@
|
|||
showdown.subParser('makehtml.anchors', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.anchors.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.anchors.before', text, options, globals).getText();
|
||||
|
||||
var writeAnchorTag = function (wholeMatch, linkText, linkId, url, m5, m6, title) {
|
||||
if (showdown.helper.isUndefined(title)) {
|
||||
title = '';
|
||||
}
|
||||
linkId = linkId.toLowerCase();
|
||||
var writeAnchorTag = function (rgx) {
|
||||
|
||||
// Special case for explicit empty url
|
||||
if (wholeMatch.search(/\(<?\s*>? ?(['"].*['"])?\)$/m) > -1) {
|
||||
url = '';
|
||||
} else if (!url) {
|
||||
if (!linkId) {
|
||||
// lower-case and turn embedded newlines into spaces
|
||||
linkId = linkText.toLowerCase().replace(/ ?\n/g, ' ');
|
||||
}
|
||||
url = '#' + linkId;
|
||||
|
||||
if (!showdown.helper.isUndefined(globals.gUrls[linkId])) {
|
||||
url = globals.gUrls[linkId];
|
||||
if (!showdown.helper.isUndefined(globals.gTitles[linkId])) {
|
||||
title = globals.gTitles[linkId];
|
||||
return function (wholeMatch1, linkText1, linkId1, url1, m5, m6, title1) {
|
||||
var evt = globals.converter._dispatch('makehtml.anchors.capture_begin', wholeMatch1, options, globals, {
|
||||
regexp: rgx,
|
||||
matches: {
|
||||
wholeMatch: wholeMatch1,
|
||||
linkText: linkText1,
|
||||
linkId: linkId1,
|
||||
url: url1,
|
||||
title: title1
|
||||
}
|
||||
} else {
|
||||
return wholeMatch;
|
||||
});
|
||||
|
||||
var wholeMatch = evt.getMatches().wholeMatch;
|
||||
var linkText = evt.getMatches().linkText;
|
||||
var linkId = evt.getMatches().linkId;
|
||||
var url = evt.getMatches().url;
|
||||
var title = evt.getMatches().title;
|
||||
|
||||
if (showdown.helper.isUndefined(title)) {
|
||||
title = '';
|
||||
}
|
||||
}
|
||||
linkId = linkId.toLowerCase();
|
||||
|
||||
//url = showdown.helper.escapeCharacters(url, '*_', false); // replaced line to improve performance
|
||||
url = url.replace(showdown.helper.regexes.asteriskDashAndColon, showdown.helper.escapeCharactersCallback);
|
||||
// Special case for explicit empty url
|
||||
if (wholeMatch.search(/\(<?\s*>? ?(['"].*['"])?\)$/m) > -1) {
|
||||
url = '';
|
||||
} else if (!url) {
|
||||
if (!linkId) {
|
||||
// lower-case and turn embedded newlines into spaces
|
||||
linkId = linkText.toLowerCase().replace(/ ?\n/g, ' ');
|
||||
}
|
||||
url = '#' + linkId;
|
||||
|
||||
var result = '<a href="' + url + '"';
|
||||
if (!showdown.helper.isUndefined(globals.gUrls[linkId])) {
|
||||
url = globals.gUrls[linkId];
|
||||
if (!showdown.helper.isUndefined(globals.gTitles[linkId])) {
|
||||
title = globals.gTitles[linkId];
|
||||
}
|
||||
} else {
|
||||
return wholeMatch;
|
||||
}
|
||||
}
|
||||
|
||||
if (title !== '' && title !== null) {
|
||||
title = title.replace(/"/g, '"');
|
||||
//title = showdown.helper.escapeCharacters(title, '*_', false); // replaced line to improve performance
|
||||
title = title.replace(showdown.helper.regexes.asteriskDashAndColon, showdown.helper.escapeCharactersCallback);
|
||||
result += ' title="' + title + '"';
|
||||
}
|
||||
//url = showdown.helper.escapeCharacters(url, '*_', false); // replaced line to improve performance
|
||||
url = url.replace(showdown.helper.regexes.asteriskDashAndColon, showdown.helper.escapeCharactersCallback);
|
||||
|
||||
// optionLinksInNewWindow only applies
|
||||
// to external links. Hash links (#) open in same page
|
||||
if (options.openLinksInNewWindow && !/^#/.test(url)) {
|
||||
// escaped _
|
||||
result += ' target="¨E95Eblank"';
|
||||
}
|
||||
var result = '<a href="' + url + '"';
|
||||
|
||||
result += '>' + linkText + '</a>';
|
||||
if (title !== '' && title !== null) {
|
||||
title = title.replace(/"/g, '"');
|
||||
//title = showdown.helper.escapeCharacters(title, '*_', false); // replaced line to improve performance
|
||||
title = title.replace(showdown.helper.regexes.asteriskDashAndColon, showdown.helper.escapeCharactersCallback);
|
||||
result += ' title="' + title + '"';
|
||||
}
|
||||
|
||||
return result;
|
||||
// optionLinksInNewWindow only applies
|
||||
// to external links. Hash links (#) open in same page
|
||||
if (options.openLinksInNewWindow && !/^#/.test(url)) {
|
||||
// escaped _
|
||||
result += ' target="¨E95Eblank"';
|
||||
}
|
||||
|
||||
result += '>' + linkText + '</a>';
|
||||
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
var referenceRegex = /\[((?:\[[^\]]*]|[^\[\]])*)] ?(?:\n *)?\[(.*?)]()()()()/g;
|
||||
// First, handle reference-style links: [link text] [id]
|
||||
text = text.replace(/\[((?:\[[^\]]*]|[^\[\]])*)] ?(?:\n *)?\[(.*?)]()()()()/g, writeAnchorTag);
|
||||
text = text.replace(referenceRegex, writeAnchorTag(referenceRegex));
|
||||
|
||||
// Next, inline-style links: [link text](url "optional title")
|
||||
// cases with crazy urls like ./image/cat1).png
|
||||
text = text.replace(/\[((?:\[[^\]]*]|[^\[\]])*)]()[ \t]*\([ \t]?<([^>]*)>(?:[ \t]*((["'])([^"]*?)\5))?[ \t]?\)/g,
|
||||
writeAnchorTag);
|
||||
var inlineRegexCrazy = /\[((?:\[[^\]]*]|[^\[\]])*)]()[ \t]*\([ \t]?<([^>]*)>(?:[ \t]*((["'])([^"]*?)\5))?[ \t]?\)/g;
|
||||
text = text.replace(inlineRegexCrazy, writeAnchorTag(inlineRegexCrazy));
|
||||
|
||||
// normal cases
|
||||
text = text.replace(/\[((?:\[[^\]]*]|[^\[\]])*)]()[ \t]*\([ \t]?<?([\S]+?(?:\([\S]*?\)[\S]*?)?)>?(?:[ \t]*((["'])([^"]*?)\5))?[ \t]?\)/g,
|
||||
writeAnchorTag);
|
||||
var inlineRegex = /\[((?:\[[^\]]*]|[^\[\]])*)]()[ \t]*\([ \t]?<?([\S]+?(?:\([\S]*?\)[\S]*?)?)>?(?:[ \t]*((["'])([^"]*?)\5))?[ \t]?\)/g;
|
||||
text = text.replace(inlineRegex, writeAnchorTag(inlineRegex));
|
||||
|
||||
// handle reference-style shortcuts: [link text]
|
||||
// These must come last in case you've also got [link test][1]
|
||||
// or [link test](/foo)
|
||||
text = text.replace(/\[([^\[\]]+)]()()()()()/g, writeAnchorTag);
|
||||
var referenceShortcutRegex = /\[([^\[\]]+)]()()()()()/g;
|
||||
text = text.replace(referenceShortcutRegex, writeAnchorTag(referenceShortcutRegex));
|
||||
|
||||
// Lastly handle GithubMentions if option is enabled
|
||||
if (options.ghMentions) {
|
||||
|
@ -93,6 +115,6 @@ showdown.subParser('makehtml.anchors', function (text, options, globals) {
|
|||
});
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('makehtml.anchors.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.anchors.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -47,12 +47,12 @@ var simpleURLRegex = /([*~_]+|\b)(((https?|ftp|dict):\/\/|www\.)[^'">\s]+?\.[^'
|
|||
showdown.subParser('makehtml.autoLinks', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.autoLinks.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.autoLinks.before', text, options, globals).getText();
|
||||
|
||||
text = text.replace(delimUrlRegex, replaceLink(options));
|
||||
text = text.replace(delimMailRegex, replaceMail(options, globals));
|
||||
|
||||
text = globals.converter._dispatch('makehtml.autoLinks.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.autoLinks.after', text, options, globals).getText();
|
||||
|
||||
return text;
|
||||
});
|
||||
|
@ -64,7 +64,7 @@ showdown.subParser('makehtml.simplifiedAutoLinks', function (text, options, glob
|
|||
return text;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('makehtml.simplifiedAutoLinks.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.simplifiedAutoLinks.before', text, options, globals).getText();
|
||||
|
||||
if (options.excludeTrailingPunctuationFromURLs) {
|
||||
text = text.replace(simpleURLRegex2, replaceLink(options));
|
||||
|
@ -73,7 +73,7 @@ showdown.subParser('makehtml.simplifiedAutoLinks', function (text, options, glob
|
|||
}
|
||||
text = text.replace(simpleMailRegex, replaceMail(options, globals));
|
||||
|
||||
text = globals.converter._dispatch('makehtml.simplifiedAutoLinks.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.simplifiedAutoLinks.after', text, options, globals).getText();
|
||||
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
showdown.subParser('makehtml.blockGamut', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.blockGamut.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.blockGamut.before', text, options, globals).getText();
|
||||
|
||||
// we parse blockquotes first so that we can have headings and hrs
|
||||
// inside blockquotes
|
||||
|
@ -26,7 +26,7 @@ showdown.subParser('makehtml.blockGamut', function (text, options, globals) {
|
|||
text = showdown.subParser('makehtml.hashHTMLBlocks')(text, options, globals);
|
||||
text = showdown.subParser('makehtml.paragraphs')(text, options, globals);
|
||||
|
||||
text = globals.converter._dispatch('makehtml.blockGamut.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.blockGamut.after', text, options, globals).getText();
|
||||
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
showdown.subParser('makehtml.blockQuotes', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.blockQuotes.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.blockQuotes.before', text, options, globals).getText();
|
||||
|
||||
// add a couple extra lines after the text and endtext mark
|
||||
text = text + '\n\n';
|
||||
|
@ -37,6 +37,6 @@ showdown.subParser('makehtml.blockQuotes', function (text, options, globals) {
|
|||
return showdown.subParser('makehtml.hashBlock')('<blockquote>\n' + bq + '\n</blockquote>', options, globals);
|
||||
});
|
||||
|
||||
text = globals.converter._dispatch('makehtml.blockQuotes.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.blockQuotes.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
showdown.subParser('makehtml.codeBlocks', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.codeBlocks.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.codeBlocks.before', text, options, globals).getText();
|
||||
|
||||
// sentinel workarounds for lack of \A and \Z, safari\khtml bug
|
||||
text += '¨0';
|
||||
|
@ -33,6 +33,6 @@ showdown.subParser('makehtml.codeBlocks', function (text, options, globals) {
|
|||
// strip sentinel
|
||||
text = text.replace(/¨0/, '');
|
||||
|
||||
text = globals.converter._dispatch('makehtml.codeBlocks.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.codeBlocks.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
showdown.subParser('makehtml.codeSpans', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.codeSpans.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.codeSpans.before', text, options, globals).getText();
|
||||
|
||||
if (typeof(text) === 'undefined') {
|
||||
text = '';
|
||||
|
@ -43,6 +43,6 @@ showdown.subParser('makehtml.codeSpans', function (text, options, globals) {
|
|||
}
|
||||
);
|
||||
|
||||
text = globals.converter._dispatch('makehtml.codeSpans.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.codeSpans.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -8,7 +8,7 @@ showdown.subParser('makehtml.completeHTMLDocument', function (text, options, glo
|
|||
return text;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('makehtml.completeHTMLDocument.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.completeHTMLDocument.before', text, options, globals).getText();
|
||||
|
||||
var doctype = 'html',
|
||||
doctypeParsed = '<!DOCTYPE HTML>\n',
|
||||
|
@ -57,6 +57,6 @@ showdown.subParser('makehtml.completeHTMLDocument', function (text, options, glo
|
|||
|
||||
text = doctypeParsed + '<html' + lang + '>\n<head>\n' + title + charset + metadata + '</head>\n<body>\n' + text.trim() + '\n</body>\n</html>';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.completeHTMLDocument.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.completeHTMLDocument.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
showdown.subParser('makehtml.detab', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.detab.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.detab.before', text, options, globals).getText();
|
||||
|
||||
// expand first n-1 tabs
|
||||
text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width
|
||||
|
@ -28,6 +28,6 @@ showdown.subParser('makehtml.detab', function (text, options, globals) {
|
|||
text = text.replace(/¨A/g, ' '); // g_tab_width
|
||||
text = text.replace(/¨B/g, '');
|
||||
|
||||
text = globals.converter._dispatch('makehtml.detab.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.detab.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
showdown.subParser('makehtml.ellipsis', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.ellipsis.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.ellipsis.before', text, options, globals).getText();
|
||||
|
||||
text = text.replace(/\.\.\./g, '…');
|
||||
|
||||
text = globals.converter._dispatch('makehtml.ellipsis.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.ellipsis.after', text, options, globals).getText();
|
||||
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ showdown.subParser('makehtml.emoji', function (text, options, globals) {
|
|||
return text;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('makehtml.emoji.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.emoji.before', text, options, globals).getText();
|
||||
|
||||
var emojiRgx = /:([\S]+?):/g;
|
||||
|
||||
|
@ -20,7 +20,7 @@ showdown.subParser('makehtml.emoji', function (text, options, globals) {
|
|||
return wm;
|
||||
});
|
||||
|
||||
text = globals.converter._dispatch('makehtml.emoji.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.emoji.after', text, options, globals).getText();
|
||||
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
showdown.subParser('makehtml.encodeAmpsAndAngles', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.before', text, options, globals).getText();
|
||||
|
||||
// Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
|
||||
// http://bumppo.net/projects/amputator/
|
||||
|
@ -18,6 +18,6 @@ showdown.subParser('makehtml.encodeAmpsAndAngles', function (text, options, glob
|
|||
// Encode >
|
||||
text = text.replace(/>/g, '>');
|
||||
|
||||
text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
*/
|
||||
showdown.subParser('makehtml.encodeBackslashEscapes', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.before', text, options, globals).getText();
|
||||
|
||||
text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
|
||||
text = text.replace(/\\([`*_{}\[\]()>#+.!~=|-])/g, showdown.helper.escapeCharactersCallback);
|
||||
|
||||
text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
showdown.subParser('makehtml.encodeCode', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.encodeCode.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.encodeCode.before', text, options, globals).getText();
|
||||
|
||||
// Encode all ampersands; HTML entities are not
|
||||
// entities within a Markdown code span.
|
||||
|
@ -18,6 +18,6 @@ showdown.subParser('makehtml.encodeCode', function (text, options, globals) {
|
|||
// Now, escape characters that are magic in Markdown:
|
||||
.replace(/([*_{}\[\]\\=~-])/g, showdown.helper.escapeCharactersCallback);
|
||||
|
||||
text = globals.converter._dispatch('makehtml.encodeCode.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.encodeCode.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.before', text, options, globals).getText();
|
||||
|
||||
// Build a regex to find HTML tags.
|
||||
var tags = /<\/?[a-z\d_:-]+(?:[\s]+[\s\S]+?)?>/gi,
|
||||
|
@ -21,6 +21,6 @@ showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes', function (t
|
|||
.replace(/([\\`*_~=|])/g, showdown.helper.escapeCharactersCallback);
|
||||
});
|
||||
|
||||
text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@ showdown.subParser('makehtml.githubCodeBlocks', function (text, options, globals
|
|||
return text;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('makehtml.githubCodeBlocks.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.githubCodeBlocks.before', text, options, globals).getText();
|
||||
|
||||
text += '¨0';
|
||||
|
||||
|
@ -42,5 +42,5 @@ showdown.subParser('makehtml.githubCodeBlocks', function (text, options, globals
|
|||
// attacklab: strip sentinel
|
||||
text = text.replace(/¨0/, '');
|
||||
|
||||
return globals.converter._dispatch('makehtml.githubCodeBlocks.after', text, options, globals);
|
||||
return globals.converter._dispatch('makehtml.githubCodeBlocks.after', text, options, globals).getText();
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
showdown.subParser('makehtml.hashBlock', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.hashBlock.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.hashBlock.before', text, options, globals).getText();
|
||||
text = text.replace(/(^\n+|\n+$)/g, '');
|
||||
text = '\n\n¨K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n';
|
||||
text = globals.converter._dispatch('makehtml.hashBlock.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.hashBlock.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
showdown.subParser('makehtml.hashCodeTags', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.hashCodeTags.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.hashCodeTags.before', text, options, globals).getText();
|
||||
|
||||
var repFunc = function (wholeMatch, match, left, right) {
|
||||
var codeblock = left + showdown.subParser('makehtml.encodeCode')(match, options, globals) + right;
|
||||
|
@ -13,6 +13,6 @@ showdown.subParser('makehtml.hashCodeTags', function (text, options, globals) {
|
|||
// Hash naked <code>
|
||||
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '<code\\b[^>]*>', '</code>', 'gim');
|
||||
|
||||
text = globals.converter._dispatch('makehtml.hashCodeTags.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.hashCodeTags.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
showdown.subParser('makehtml.hashHTMLBlocks', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.hashHTMLBlocks.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.hashHTMLBlocks.before', text, options, globals).getText();
|
||||
|
||||
var blockTags = [
|
||||
'pre',
|
||||
|
@ -93,6 +93,6 @@ showdown.subParser('makehtml.hashHTMLBlocks', function (text, options, globals)
|
|||
text = text.replace(/(?:\n\n)( {0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
|
||||
showdown.subParser('makehtml.hashElement')(text, options, globals));
|
||||
|
||||
text = globals.converter._dispatch('makehtml.hashHTMLBlocks.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.hashHTMLBlocks.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
showdown.subParser('makehtml.hashHTMLSpans', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.hashHTMLSpans.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.hashHTMLSpans.before', text, options, globals).getText();
|
||||
|
||||
function hashHTMLSpan (html) {
|
||||
return '¨C' + (globals.gHtmlSpans.push(html) - 1) + 'C';
|
||||
|
@ -31,7 +31,7 @@ showdown.subParser('makehtml.hashHTMLSpans', function (text, options, globals) {
|
|||
|
||||
/*showdown.helper.matchRecursiveRegExp(text, '<code\\b[^>]*>', '</code>', 'gi');*/
|
||||
|
||||
text = globals.converter._dispatch('makehtml.hashHTMLSpans.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.hashHTMLSpans.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
||||
|
@ -40,7 +40,7 @@ showdown.subParser('makehtml.hashHTMLSpans', function (text, options, globals) {
|
|||
*/
|
||||
showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.unhashHTMLSpans.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.unhashHTMLSpans.before', text, options, globals).getText();
|
||||
|
||||
for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
|
||||
var repText = globals.gHtmlSpans[i],
|
||||
|
@ -59,6 +59,6 @@ showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals)
|
|||
text = text.replace('¨C' + i + 'C', repText);
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('makehtml.unhashHTMLSpans.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.unhashHTMLSpans.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
showdown.subParser('makehtml.hashPreCodeTags', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.hashPreCodeTags.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.hashPreCodeTags.before', text, options, globals).getText();
|
||||
|
||||
var repFunc = function (wholeMatch, match, left, right) {
|
||||
// encode html entities
|
||||
|
@ -14,6 +14,6 @@ showdown.subParser('makehtml.hashPreCodeTags', function (text, options, globals)
|
|||
// Hash <pre><code>
|
||||
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<pre\\b[^>]*>\\s*<code\\b[^>]*>', '^ {0,3}</code>\\s*</pre>', 'gim');
|
||||
|
||||
text = globals.converter._dispatch('makehtml.hashPreCodeTags.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.hashPreCodeTags.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
showdown.subParser('makehtml.headers', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.headers.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.headers.before', text, options, globals).getText();
|
||||
|
||||
var headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart),
|
||||
|
||||
|
@ -121,6 +121,6 @@ showdown.subParser('makehtml.headers', function (text, options, globals) {
|
|||
return title;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('makehtml.headers.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.headers.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
*/
|
||||
showdown.subParser('makehtml.horizontalRule', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.horizontalRule.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.horizontalRule.before', text, options, globals).getText();
|
||||
|
||||
var key = showdown.subParser('makehtml.hashBlock')('<hr />', options, globals);
|
||||
text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key);
|
||||
text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
|
||||
text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
|
||||
|
||||
text = globals.converter._dispatch('makehtml.horizontalRule.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.horizontalRule.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
showdown.subParser('makehtml.images', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.images.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.images.before', text, options, globals).getText();
|
||||
|
||||
var inlineRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<?([\S]+?(?:\([\S]*?\)[\S]*?)?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(["'])([^"]*?)\6)?[ \t]?\)/g,
|
||||
crazyRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<([^>]*)>(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(?:(["'])([^"]*?)\6))?[ \t]?\)/g,
|
||||
|
@ -99,6 +99,6 @@ showdown.subParser('makehtml.images', function (text, options, globals) {
|
|||
// handle reference-style shortcuts: ![img text]
|
||||
text = text.replace(refShortcutRegExp, writeImageTag);
|
||||
|
||||
text = globals.converter._dispatch('makehtml.images.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.images.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
showdown.subParser('makehtml.italicsAndBold', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.italicsAndBold.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.italicsAndBold.before', text, options, globals).getText();
|
||||
|
||||
// it's faster to have 3 separate regexes for each case than have just one
|
||||
// because of backtracing, in some cases, it could lead to an exponential effect
|
||||
|
@ -65,6 +65,6 @@ showdown.subParser('makehtml.italicsAndBold', function (text, options, globals)
|
|||
}
|
||||
|
||||
|
||||
text = globals.converter._dispatch('makehtml.italicsAndBold.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.italicsAndBold.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -175,7 +175,7 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
}
|
||||
|
||||
/** Start of list parsing **/
|
||||
text = globals.converter._dispatch('lists.before', text, options, globals);
|
||||
text = globals.converter._dispatch('lists.before', text, options, globals).getText();
|
||||
// add sentinel to hack around khtml/safari bug:
|
||||
// http://bugs.webkit.org/show_bug.cgi?id=11231
|
||||
text += '¨0';
|
||||
|
@ -198,6 +198,6 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
|
||||
// strip sentinel
|
||||
text = text.replace(/¨0/, '');
|
||||
text = globals.converter._dispatch('makehtml.lists.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.lists.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -8,7 +8,7 @@ showdown.subParser('makehtml.metadata', function (text, options, globals) {
|
|||
return text;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('makehtml.metadata.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.metadata.before', text, options, globals).getText();
|
||||
|
||||
function parseMetadataContents (content) {
|
||||
// raw is raw so it's not changed in any way
|
||||
|
@ -44,6 +44,6 @@ showdown.subParser('makehtml.metadata', function (text, options, globals) {
|
|||
|
||||
text = text.replace(/¨M/g, '');
|
||||
|
||||
text = globals.converter._dispatch('makehtml.metadata.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.metadata.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
showdown.subParser('makehtml.outdent', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.outdent.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.outdent.before', text, options, globals).getText();
|
||||
|
||||
// attacklab: hack around Konqueror 3.5.4 bug:
|
||||
// "----------bug".replace(/^-/g,"") == "bug"
|
||||
|
@ -12,6 +12,6 @@ showdown.subParser('makehtml.outdent', function (text, options, globals) {
|
|||
// attacklab: clean up hack
|
||||
text = text.replace(/¨0/g, '');
|
||||
|
||||
text = globals.converter._dispatch('makehtml.outdent.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.outdent.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
showdown.subParser('makehtml.paragraphs', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('makehtml.paragraphs.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.paragraphs.before', text, options, globals).getText();
|
||||
// Strip leading and trailing lines:
|
||||
text = text.replace(/^\n+/g, '');
|
||||
text = text.replace(/\n+$/g, '');
|
||||
|
@ -66,5 +66,5 @@ showdown.subParser('makehtml.paragraphs', function (text, options, globals) {
|
|||
// Strip leading and trailing lines:
|
||||
text = text.replace(/^\n+/g, '');
|
||||
text = text.replace(/\n+$/g, '');
|
||||
return globals.converter._dispatch('makehtml.paragraphs.after', text, options, globals);
|
||||
return globals.converter._dispatch('makehtml.paragraphs.after', text, options, globals).getText();
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
showdown.subParser('makehtml.spanGamut', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
text = globals.converter._dispatch('smakehtml.panGamut.before', text, options, globals);
|
||||
text = globals.converter._dispatch('smakehtml.panGamut.before', text, options, globals).getText();
|
||||
text = showdown.subParser('makehtml.codeSpans')(text, options, globals);
|
||||
text = showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes')(text, options, globals);
|
||||
text = showdown.subParser('makehtml.encodeBackslashEscapes')(text, options, globals);
|
||||
|
@ -44,6 +44,6 @@ showdown.subParser('makehtml.spanGamut', function (text, options, globals) {
|
|||
text = text.replace(/ +\n/g, '<br />\n');
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('makehtml.spanGamut.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.spanGamut.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -9,9 +9,9 @@ showdown.subParser('makehtml.strikethrough', function (text, options, globals) {
|
|||
}
|
||||
|
||||
if (options.strikethrough) {
|
||||
text = globals.converter._dispatch('makehtml.strikethrough.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.strikethrough.before', text, options, globals).getText();
|
||||
text = text.replace(/(?:~){2}([\s\S]+?)(?:~){2}/g, function (wm, txt) { return parseInside(txt); });
|
||||
text = globals.converter._dispatch('makehtml.strikethrough.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.strikethrough.after', text, options, globals).getText();
|
||||
}
|
||||
|
||||
return text;
|
||||
|
|
|
@ -70,6 +70,7 @@ showdown.subParser('makehtml.tables', function (text, options, globals) {
|
|||
tableLines[i] = tableLines[i].replace(/\|[ \t]*$/, '');
|
||||
}
|
||||
// parse code spans first, but we only support one line code spans
|
||||
|
||||
tableLines[i] = showdown.subParser('makehtml.codeSpans')(tableLines[i], options, globals);
|
||||
}
|
||||
|
||||
|
@ -125,7 +126,7 @@ showdown.subParser('makehtml.tables', function (text, options, globals) {
|
|||
return buildTable(headers, cells);
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('makehtml.tables.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.tables.before', text, options, globals).getText();
|
||||
|
||||
// find escaped pipe characters
|
||||
text = text.replace(/\\(\|)/g, showdown.helper.escapeCharactersCallback);
|
||||
|
@ -136,7 +137,7 @@ showdown.subParser('makehtml.tables', function (text, options, globals) {
|
|||
// parse one column tables
|
||||
text = text.replace(singeColTblRgx, parseTable);
|
||||
|
||||
text = globals.converter._dispatch('makehtml.tables.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.tables.after', text, options, globals).getText();
|
||||
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@ showdown.subParser('makehtml.underline', function (text, options, globals) {
|
|||
return text;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('makehtml.underline.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.underline.before', text, options, globals).getText();
|
||||
|
||||
if (options.literalMidWordUnderscores) {
|
||||
text = text.replace(/\b_?__(\S[\s\S]*)___?\b/g, function (wm, txt) {
|
||||
|
@ -20,7 +20,7 @@ showdown.subParser('makehtml.underline', function (text, options, globals) {
|
|||
// escape remaining underscores to prevent them being parsed by italic and bold
|
||||
text = text.replace(/(_)/g, showdown.helper.escapeCharactersCallback);
|
||||
|
||||
text = globals.converter._dispatch('makehtml.underline.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.underline.after', text, options, globals).getText();
|
||||
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
*/
|
||||
showdown.subParser('makehtml.unescapeSpecialChars', function (text, options, globals) {
|
||||
'use strict';
|
||||
text = globals.converter._dispatch('makehtml.unescapeSpecialChars.before', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.unescapeSpecialChars.before', text, options, globals).getText();
|
||||
|
||||
text = text.replace(/¨E(\d+)E/g, function (wholeMatch, m1) {
|
||||
var charCodeToReplace = parseInt(m1);
|
||||
return String.fromCharCode(charCodeToReplace);
|
||||
});
|
||||
|
||||
text = globals.converter._dispatch('makehtml.unescapeSpecialChars.after', text, options, globals);
|
||||
text = globals.converter._dispatch('makehtml.unescapeSpecialChars.after', text, options, globals).getText();
|
||||
return text;
|
||||
});
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -126,19 +126,19 @@ describe('showdown.Converter', function () {
|
|||
|
||||
describe('events', function () {
|
||||
var events = [
|
||||
'anchors',
|
||||
'autoLinks',
|
||||
'blockGamut',
|
||||
'blockQuotes',
|
||||
'codeBlocks',
|
||||
'codeSpans',
|
||||
'githubCodeBlocks',
|
||||
'headers',
|
||||
'images',
|
||||
'italicsAndBold',
|
||||
'lists',
|
||||
'paragraph',
|
||||
'spanGamut'
|
||||
'makehtml.anchors',
|
||||
'makehtml.autoLinks',
|
||||
'makehtml.blockGamut',
|
||||
'makehtml.blockQuotes',
|
||||
'makehtml.codeBlocks',
|
||||
'makehtml.codeSpans',
|
||||
'makehtml.githubCodeBlocks',
|
||||
'makehtml.headers',
|
||||
'makehtml.images',
|
||||
'makehtml.italicsAndBold',
|
||||
'makehtml.lists',
|
||||
'makehtml.paragraph',
|
||||
'makehtml.spanGamut'
|
||||
//'strikeThrough',
|
||||
//'tables'
|
||||
];
|
||||
|
@ -151,8 +151,10 @@ describe('showdown.Converter', function () {
|
|||
function runListener (name) {
|
||||
it('should listen to ' + name, function () {
|
||||
var converter = new showdown.Converter();
|
||||
converter.listen(name, function (evtName, text) {
|
||||
evtName.should.equal(name);
|
||||
converter.listen(name, function (event) {
|
||||
var evtName = event.getName();
|
||||
var text = event.getCapturedText();
|
||||
evtName.should.equal(name.toLowerCase());
|
||||
text.should.match(/^[\s\S]*foo[\s\S]*$/);
|
||||
return text;
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user