diff --git a/dist/showdown.js b/dist/showdown.js index 2e0f6bf..675c45f 100644 Binary files a/dist/showdown.js and b/dist/showdown.js differ diff --git a/dist/showdown.js.map b/dist/showdown.js.map index ec138f8..4cd9ef3 100644 Binary files a/dist/showdown.js.map and b/dist/showdown.js.map differ diff --git a/dist/showdown.min.js b/dist/showdown.min.js index f247d69..16c3cb5 100644 Binary files a/dist/showdown.min.js and b/dist/showdown.min.js differ diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index d2d2444..5806330 100644 Binary files a/dist/showdown.min.js.map and b/dist/showdown.min.js.map differ diff --git a/src/converter.js b/src/converter.js index 8aa9d61..58e4e77 100644 --- a/src/converter.js +++ b/src/converter.js @@ -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; }; /** diff --git a/src/helpers.js b/src/helpers.js index 6159c23..820b874 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -396,6 +396,69 @@ showdown.helper.unescapeHTMLEntities = function (txt) { .replace(/&/g, '&'); }; +/** + * Showdown's Event Object + * @param {string} name Name of the event + * @param {{}} params optional. params of the event + * @constructor + */ +showdown.helper.Event = function (name, text, params) { + 'use strict'; + + /** + * Get the name of the event + * @returns {string} + */ + this.getName = function () { + return name; + }; + + this.getEventName = function () { + return name; + }; + + var regexp = params.regexp || null; + var matches = params.matches || {}; + var options = params.options || {}; + var converter = params.converter || null; + var globals = params.globals || {}; + + this._stopExecution = false; + + this.parsedText = params.parsedText || null; + + this.getRegexp = function () { + return regexp; + }; + this.getOptions = function () { + return options; + }; + this.getConverter = function () { + return converter; + }; + this.getGlobals = function () { + return globals; + }; + this.getCapturedText = function () { + return text; + }; + this.getText = function () { + return text; + }; + this.setText = function (newText) { + text = newText; + }; + this.getMatches = function () { + return matches; + }; + this.setMatches = function (newMatches) { + matches = newMatches; + }; + this.preventDefault = function (bool) { + this._stopExecution = !bool; + }; +}; + /** * POLYFILLS */ @@ -1604,6 +1667,6 @@ showdown.helper.emojis = { 'zzz':'\ud83d\udca4', /* special emojis :P */ - 'octocat': '', + 'octocat': '', 'showdown': '' }; diff --git a/src/subParsers/makehtml/anchors.js b/src/subParsers/makehtml/anchors.js index 1adc213..e96f57d 100644 --- a/src/subParsers/makehtml/anchors.js +++ b/src/subParsers/makehtml/anchors.js @@ -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(/\(? ?(['"].*['"])?\)$/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(/\(? ?(['"].*['"])?\)$/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 = ''; + 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 + ''; + + 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]??(?:[ \t]*((["'])([^"]*?)\5))?[ \t]?\)/g, - writeAnchorTag); + var inlineRegex = /\[((?:\[[^\]]*]|[^\[\]])*)]()[ \t]*\([ \t]??(?:[ \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; }); diff --git a/src/subParsers/makehtml/autoLinks.js b/src/subParsers/makehtml/autoLinks.js index 0896d7a..ca39193 100644 --- a/src/subParsers/makehtml/autoLinks.js +++ b/src/subParsers/makehtml/autoLinks.js @@ -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; }); diff --git a/src/subParsers/makehtml/blockGamut.js b/src/subParsers/makehtml/blockGamut.js index 2f46771..7a9b2b6 100644 --- a/src/subParsers/makehtml/blockGamut.js +++ b/src/subParsers/makehtml/blockGamut.js @@ -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; }); diff --git a/src/subParsers/makehtml/blockQuotes.js b/src/subParsers/makehtml/blockQuotes.js index b372401..256f3d7 100644 --- a/src/subParsers/makehtml/blockQuotes.js +++ b/src/subParsers/makehtml/blockQuotes.js @@ -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')('
\n' + bq + '\n
', 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; }); diff --git a/src/subParsers/makehtml/codeBlocks.js b/src/subParsers/makehtml/codeBlocks.js index 271d092..ed9da66 100644 --- a/src/subParsers/makehtml/codeBlocks.js +++ b/src/subParsers/makehtml/codeBlocks.js @@ -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; }); diff --git a/src/subParsers/makehtml/codeSpans.js b/src/subParsers/makehtml/codeSpans.js index 54f2e94..8da5f84 100644 --- a/src/subParsers/makehtml/codeSpans.js +++ b/src/subParsers/makehtml/codeSpans.js @@ -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; }); diff --git a/src/subParsers/makehtml/completeHTMLDocument.js b/src/subParsers/makehtml/completeHTMLDocument.js index 464e94a..79cb3e7 100644 --- a/src/subParsers/makehtml/completeHTMLDocument.js +++ b/src/subParsers/makehtml/completeHTMLDocument.js @@ -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 = '\n', @@ -57,6 +57,6 @@ showdown.subParser('makehtml.completeHTMLDocument', function (text, options, glo text = doctypeParsed + '\n\n' + title + charset + metadata + '\n\n' + text.trim() + '\n\n'; - text = globals.converter._dispatch('makehtml.completeHTMLDocument.after', text, options, globals); + text = globals.converter._dispatch('makehtml.completeHTMLDocument.after', text, options, globals).getText(); return text; }); diff --git a/src/subParsers/makehtml/detab.js b/src/subParsers/makehtml/detab.js index 44dc86c..41e1180 100644 --- a/src/subParsers/makehtml/detab.js +++ b/src/subParsers/makehtml/detab.js @@ -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; }); diff --git a/src/subParsers/makehtml/ellipsis.js b/src/subParsers/makehtml/ellipsis.js index 39d1292..68856a6 100644 --- a/src/subParsers/makehtml/ellipsis.js +++ b/src/subParsers/makehtml/ellipsis.js @@ -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; }); diff --git a/src/subParsers/makehtml/emoji.js b/src/subParsers/makehtml/emoji.js index 5746509..0a2523f 100644 --- a/src/subParsers/makehtml/emoji.js +++ b/src/subParsers/makehtml/emoji.js @@ -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; }); diff --git a/src/subParsers/makehtml/encodeAmpsAndAngles.js b/src/subParsers/makehtml/encodeAmpsAndAngles.js index 086d236..e69322d 100644 --- a/src/subParsers/makehtml/encodeAmpsAndAngles.js +++ b/src/subParsers/makehtml/encodeAmpsAndAngles.js @@ -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; }); diff --git a/src/subParsers/makehtml/encodeBackslashEscapes.js b/src/subParsers/makehtml/encodeBackslashEscapes.js index 3a7bc23..4a888e2 100644 --- a/src/subParsers/makehtml/encodeBackslashEscapes.js +++ b/src/subParsers/makehtml/encodeBackslashEscapes.js @@ -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; }); diff --git a/src/subParsers/makehtml/encodeCode.js b/src/subParsers/makehtml/encodeCode.js index 23899e2..84afaf7 100644 --- a/src/subParsers/makehtml/encodeCode.js +++ b/src/subParsers/makehtml/encodeCode.js @@ -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; }); diff --git a/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js b/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js index 610fbe7..6819588 100644 --- a/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js +++ b/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js @@ -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; }); diff --git a/src/subParsers/makehtml/githubCodeBlocks.js b/src/subParsers/makehtml/githubCodeBlocks.js index 75617ba..660ba75 100644 --- a/src/subParsers/makehtml/githubCodeBlocks.js +++ b/src/subParsers/makehtml/githubCodeBlocks.js @@ -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(); }); diff --git a/src/subParsers/makehtml/hashBlock.js b/src/subParsers/makehtml/hashBlock.js index c998d82..c14948f 100644 --- a/src/subParsers/makehtml/hashBlock.js +++ b/src/subParsers/makehtml/hashBlock.js @@ -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; }); diff --git a/src/subParsers/makehtml/hashCodeTags.js b/src/subParsers/makehtml/hashCodeTags.js index 36c18e4..6a77042 100644 --- a/src/subParsers/makehtml/hashCodeTags.js +++ b/src/subParsers/makehtml/hashCodeTags.js @@ -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 text = showdown.helper.replaceRecursiveRegExp(text, repFunc, ']*>', '', 'gim'); - text = globals.converter._dispatch('makehtml.hashCodeTags.after', text, options, globals); + text = globals.converter._dispatch('makehtml.hashCodeTags.after', text, options, globals).getText(); return text; }); diff --git a/src/subParsers/makehtml/hashHTMLBlocks.js b/src/subParsers/makehtml/hashHTMLBlocks.js index fadd57a..0d18d86 100644 --- a/src/subParsers/makehtml/hashHTMLBlocks.js +++ b/src/subParsers/makehtml/hashHTMLBlocks.js @@ -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; }); diff --git a/src/subParsers/makehtml/hashHTMLSpans.js b/src/subParsers/makehtml/hashHTMLSpans.js index 0745d7c..0adb324 100644 --- a/src/subParsers/makehtml/hashHTMLSpans.js +++ b/src/subParsers/makehtml/hashHTMLSpans.js @@ -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, ']*>', '', '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; }); diff --git a/src/subParsers/makehtml/hashPreCodeTags.js b/src/subParsers/makehtml/hashPreCodeTags.js index d8e4eab..e989ea9 100644 --- a/src/subParsers/makehtml/hashPreCodeTags.js +++ b/src/subParsers/makehtml/hashPreCodeTags.js @@ -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

   text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}]*>\\s*]*>', '^ {0,3}\\s*
', 'gim'); - text = globals.converter._dispatch('makehtml.hashPreCodeTags.after', text, options, globals); + text = globals.converter._dispatch('makehtml.hashPreCodeTags.after', text, options, globals).getText(); return text; }); diff --git a/src/subParsers/makehtml/headers.js b/src/subParsers/makehtml/headers.js index a3aec07..e9f7aeb 100644 --- a/src/subParsers/makehtml/headers.js +++ b/src/subParsers/makehtml/headers.js @@ -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; }); diff --git a/src/subParsers/makehtml/horizontalRule.js b/src/subParsers/makehtml/horizontalRule.js index 7f076ff..fc87fd2 100644 --- a/src/subParsers/makehtml/horizontalRule.js +++ b/src/subParsers/makehtml/horizontalRule.js @@ -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')('
', 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; }); diff --git a/src/subParsers/makehtml/images.js b/src/subParsers/makehtml/images.js index 8380404..6ae02ef 100644 --- a/src/subParsers/makehtml/images.js +++ b/src/subParsers/makehtml/images.js @@ -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]??(?: =([*\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; }); diff --git a/src/subParsers/makehtml/italicsAndBold.js b/src/subParsers/makehtml/italicsAndBold.js index 12b8e0e..7a5d317 100644 --- a/src/subParsers/makehtml/italicsAndBold.js +++ b/src/subParsers/makehtml/italicsAndBold.js @@ -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; }); diff --git a/src/subParsers/makehtml/lists.js b/src/subParsers/makehtml/lists.js index be7e84a..224f795 100644 --- a/src/subParsers/makehtml/lists.js +++ b/src/subParsers/makehtml/lists.js @@ -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; }); diff --git a/src/subParsers/makehtml/metadata.js b/src/subParsers/makehtml/metadata.js index e248837..6f2405f 100644 --- a/src/subParsers/makehtml/metadata.js +++ b/src/subParsers/makehtml/metadata.js @@ -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; }); diff --git a/src/subParsers/makehtml/outdent.js b/src/subParsers/makehtml/outdent.js index 5bdc9f0..67f4106 100644 --- a/src/subParsers/makehtml/outdent.js +++ b/src/subParsers/makehtml/outdent.js @@ -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; }); diff --git a/src/subParsers/makehtml/paragraphs.js b/src/subParsers/makehtml/paragraphs.js index 4140285..81acdf3 100644 --- a/src/subParsers/makehtml/paragraphs.js +++ b/src/subParsers/makehtml/paragraphs.js @@ -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(); }); diff --git a/src/subParsers/makehtml/spanGamut.js b/src/subParsers/makehtml/spanGamut.js index be4a786..038743d 100644 --- a/src/subParsers/makehtml/spanGamut.js +++ b/src/subParsers/makehtml/spanGamut.js @@ -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, '
\n'); } - text = globals.converter._dispatch('makehtml.spanGamut.after', text, options, globals); + text = globals.converter._dispatch('makehtml.spanGamut.after', text, options, globals).getText(); return text; }); diff --git a/src/subParsers/makehtml/strikethrough.js b/src/subParsers/makehtml/strikethrough.js index b45d707..a6251fb 100644 --- a/src/subParsers/makehtml/strikethrough.js +++ b/src/subParsers/makehtml/strikethrough.js @@ -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; diff --git a/src/subParsers/makehtml/tables.js b/src/subParsers/makehtml/tables.js index 060464f..eb2a4b7 100644 --- a/src/subParsers/makehtml/tables.js +++ b/src/subParsers/makehtml/tables.js @@ -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; }); diff --git a/src/subParsers/makehtml/underline.js b/src/subParsers/makehtml/underline.js index f832cb1..ad7f654 100644 --- a/src/subParsers/makehtml/underline.js +++ b/src/subParsers/makehtml/underline.js @@ -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; }); diff --git a/src/subParsers/makehtml/unescapeSpecialChars.js b/src/subParsers/makehtml/unescapeSpecialChars.js index 8fc266e..b96144e 100644 --- a/src/subParsers/makehtml/unescapeSpecialChars.js +++ b/src/subParsers/makehtml/unescapeSpecialChars.js @@ -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; }); diff --git a/test/functional/makehtml/cases/features/emojis/special.html b/test/functional/makehtml/cases/features/emojis/special.html index 236738f..b591c21 100644 --- a/test/functional/makehtml/cases/features/emojis/special.html +++ b/test/functional/makehtml/cases/features/emojis/special.html @@ -1,2 +1,2 @@

this is showdown's emoji

-

and this is github's emoji

\ No newline at end of file +

and this is github's emoji

diff --git a/test/unit/showdown.Converter.js b/test/unit/showdown.Converter.js index d215441..b6ee9ee 100644 --- a/test/unit/showdown.Converter.js +++ b/test/unit/showdown.Converter.js @@ -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; })