feature(evt_listeners): make globals var accessible to listeners

This commit is contained in:
Estevão Soares dos Santos 2016-03-20 17:08:44 +00:00
parent 452c4285f4
commit e0726a6e42
20 changed files with 33 additions and 32 deletions

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

@ -195,12 +195,13 @@ showdown.Converter = function (converterOptions) {
* @param {string} evtName Event name * @param {string} evtName Event name
* @param {string} text Text * @param {string} text Text
* @param {{}} options Converter Options * @param {{}} options Converter Options
* @param {{}} globals
* @returns {string} * @returns {string}
*/ */
this._dispatch = function dispatch (evtName, text, options) { this._dispatch = function dispatch (evtName, text, options, globals) {
if (listeners.hasOwnProperty(evtName)) { if (listeners.hasOwnProperty(evtName)) {
for (var ei = 0; ei < listeners[evtName].length; ++ei) { for (var ei = 0; ei < listeners[evtName].length; ++ei) {
var nText = listeners[evtName][ei](evtName, text, this, options); var nText = listeners[evtName][ei](evtName, text, this, options, globals);
if (nText && typeof nText !== 'undefined') { if (nText && typeof nText !== 'undefined') {
text = nText; text = nText;
} }

View File

@ -4,7 +4,7 @@
showdown.subParser('anchors', function (text, options, globals) { showdown.subParser('anchors', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('anchors.before', text, options); text = globals.converter._dispatch('anchors.before', text, options, globals);
var writeAnchorTag = function (wholeMatch, m1, m2, m3, m4, m5, m6, m7) { var writeAnchorTag = function (wholeMatch, m1, m2, m3, m4, m5, m6, m7) {
if (showdown.helper.isUndefined(m7)) { if (showdown.helper.isUndefined(m7)) {
@ -128,6 +128,6 @@ showdown.subParser('anchors', function (text, options, globals) {
*/ */
text = text.replace(/(\[([^\[\]]+)])()()()()()/g, writeAnchorTag); text = text.replace(/(\[([^\[\]]+)])()()()()()/g, writeAnchorTag);
text = globals.converter._dispatch('anchors.after', text, options); text = globals.converter._dispatch('anchors.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,7 +1,7 @@
showdown.subParser('autoLinks', function (text, options, globals) { showdown.subParser('autoLinks', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('autoLinks.before', text, options); text = globals.converter._dispatch('autoLinks.before', text, options, globals);
var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)(?=\s|$)(?!["<>])/gi, var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)(?=\s|$)(?!["<>])/gi,
delimUrlRegex = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi, delimUrlRegex = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
@ -23,7 +23,7 @@ showdown.subParser('autoLinks', function (text, options, globals) {
return showdown.subParser('encodeEmailAddress')(unescapedStr); return showdown.subParser('encodeEmailAddress')(unescapedStr);
} }
text = globals.converter._dispatch('autoLinks.after', text, options); text = globals.converter._dispatch('autoLinks.after', text, options, globals);
return text; return text;
}); });

View File

@ -5,7 +5,7 @@
showdown.subParser('blockGamut', function (text, options, globals) { showdown.subParser('blockGamut', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('blockGamut.before', text, options); text = globals.converter._dispatch('blockGamut.before', text, options, globals);
// we parse blockquotes first so that we can have headings and hrs // we parse blockquotes first so that we can have headings and hrs
// inside blockquotes // inside blockquotes
@ -29,7 +29,7 @@ showdown.subParser('blockGamut', function (text, options, globals) {
text = showdown.subParser('hashHTMLBlocks')(text, options, globals); text = showdown.subParser('hashHTMLBlocks')(text, options, globals);
text = showdown.subParser('paragraphs')(text, options, globals); text = showdown.subParser('paragraphs')(text, options, globals);
text = globals.converter._dispatch('blockGamut.after', text, options); text = globals.converter._dispatch('blockGamut.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,7 +1,7 @@
showdown.subParser('blockQuotes', function (text, options, globals) { showdown.subParser('blockQuotes', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('blockQuotes.before', text, options); text = globals.converter._dispatch('blockQuotes.before', text, options, globals);
/* /*
text = text.replace(/ text = text.replace(/
( // Wrap whole match in $1 ( // Wrap whole match in $1
@ -42,6 +42,6 @@ showdown.subParser('blockQuotes', function (text, options, globals) {
return showdown.subParser('hashBlock')('<blockquote>\n' + bq + '\n</blockquote>', options, globals); return showdown.subParser('hashBlock')('<blockquote>\n' + bq + '\n</blockquote>', options, globals);
}); });
text = globals.converter._dispatch('blockQuotes.after', text, options); text = globals.converter._dispatch('blockQuotes.after', text, options, globals);
return text; return text;
}); });

View File

@ -4,7 +4,7 @@
showdown.subParser('codeBlocks', function (text, options, globals) { showdown.subParser('codeBlocks', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('codeBlocks.before', text, options); text = globals.converter._dispatch('codeBlocks.before', text, options, globals);
/* /*
text = text.replace(text, text = text.replace(text,
/(?:\n\n|^) /(?:\n\n|^)
@ -45,6 +45,6 @@ showdown.subParser('codeBlocks', function (text, options, globals) {
// attacklab: strip sentinel // attacklab: strip sentinel
text = text.replace(/~0/, ''); text = text.replace(/~0/, '');
text = globals.converter._dispatch('codeBlocks.after', text, options); text = globals.converter._dispatch('codeBlocks.after', text, options, globals);
return text; return text;
}); });

View File

@ -26,7 +26,7 @@
showdown.subParser('codeSpans', function (text, options, globals) { showdown.subParser('codeSpans', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('codeSpans.before', text, options); text = globals.converter._dispatch('codeSpans.before', text, options, globals);
/* /*
text = text.replace(/ text = text.replace(/
@ -50,6 +50,6 @@ showdown.subParser('codeSpans', function (text, options, globals) {
} }
); );
text = globals.converter._dispatch('codeSpans.after', text, options); text = globals.converter._dispatch('codeSpans.after', text, options, globals);
return text; return text;
}); });

View File

@ -16,7 +16,7 @@ showdown.subParser('githubCodeBlocks', function (text, options, globals) {
return text; return text;
} }
text = globals.converter._dispatch('githubCodeBlocks.before', text, options); text = globals.converter._dispatch('githubCodeBlocks.before', text, options, globals);
text += '~0'; text += '~0';
@ -42,5 +42,5 @@ showdown.subParser('githubCodeBlocks', function (text, options, globals) {
// attacklab: strip sentinel // attacklab: strip sentinel
text = text.replace(/~0/, ''); text = text.replace(/~0/, '');
return globals.converter._dispatch('githubCodeBlocks.after', text, options); return globals.converter._dispatch('githubCodeBlocks.after', text, options, globals);
}); });

View File

@ -1,7 +1,7 @@
showdown.subParser('headers', function (text, options, globals) { showdown.subParser('headers', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('headers.before', text, options); text = globals.converter._dispatch('headers.before', text, options, globals);
var prefixHeader = options.prefixHeaderId, var prefixHeader = options.prefixHeaderId,
headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart), headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart),
@ -70,6 +70,6 @@ showdown.subParser('headers', function (text, options, globals) {
return title; return title;
} }
text = globals.converter._dispatch('headers.after', text, options); text = globals.converter._dispatch('headers.after', text, options, globals);
return text; return text;
}); });

View File

@ -4,7 +4,7 @@
showdown.subParser('images', function (text, options, globals) { showdown.subParser('images', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('images.before', text, options); text = globals.converter._dispatch('images.before', text, options, globals);
var inlineRegExp = /!\[(.*?)]\s?\([ \t]*()<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g, var inlineRegExp = /!\[(.*?)]\s?\([ \t]*()<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g,
referenceRegExp = /!\[(.*?)][ ]?(?:\n[ ]*)?\[(.*?)]()()()()()/g; referenceRegExp = /!\[(.*?)][ ]?(?:\n[ ]*)?\[(.*?)]()()()()()/g;
@ -72,6 +72,6 @@ showdown.subParser('images', function (text, options, globals) {
// Next, handle inline images: ![alt text](url =<width>x<height> "optional title") // Next, handle inline images: ![alt text](url =<width>x<height> "optional title")
text = text.replace(inlineRegExp, writeImageTag); text = text.replace(inlineRegExp, writeImageTag);
text = globals.converter._dispatch('images.after', text, options); text = globals.converter._dispatch('images.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,7 +1,7 @@
showdown.subParser('italicsAndBold', function (text, options, globals) { showdown.subParser('italicsAndBold', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('italicsAndBold.before', text, options); text = globals.converter._dispatch('italicsAndBold.before', text, options, globals);
if (options.literalMidWordUnderscores) { if (options.literalMidWordUnderscores) {
//underscores //underscores
@ -18,6 +18,6 @@ showdown.subParser('italicsAndBold', function (text, options, globals) {
text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>'); text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>');
} }
text = globals.converter._dispatch('italicsAndBold.after', text, options); text = globals.converter._dispatch('italicsAndBold.after', text, options, globals);
return text; return text;
}); });

View File

@ -4,7 +4,7 @@
showdown.subParser('lists', function (text, options, globals) { showdown.subParser('lists', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('lists.before', text, options); text = globals.converter._dispatch('lists.before', text, options, globals);
/** /**
* Process the contents of a single ordered or unordered list, splitting it * Process the contents of a single ordered or unordered list, splitting it
* into individual list items. * into individual list items.
@ -159,6 +159,6 @@ showdown.subParser('lists', function (text, options, globals) {
// attacklab: strip sentinel // attacklab: strip sentinel
text = text.replace(/~0/, ''); text = text.replace(/~0/, '');
text = globals.converter._dispatch('lists.after', text, options); text = globals.converter._dispatch('lists.after', text, options, globals);
return text; return text;
}); });

View File

@ -4,7 +4,7 @@
showdown.subParser('paragraphs', function (text, options, globals) { showdown.subParser('paragraphs', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('paragraphs.before', text, options); text = globals.converter._dispatch('paragraphs.before', text, options, globals);
// Strip leading and trailing lines: // Strip leading and trailing lines:
text = text.replace(/^\n+/g, ''); text = text.replace(/^\n+/g, '');
text = text.replace(/\n+$/g, ''); text = text.replace(/\n+$/g, '');
@ -62,5 +62,5 @@ showdown.subParser('paragraphs', function (text, options, globals) {
// Strip leading and trailing lines: // Strip leading and trailing lines:
text = text.replace(/^\n+/g, ''); text = text.replace(/^\n+/g, '');
text = text.replace(/\n+$/g, ''); text = text.replace(/\n+$/g, '');
return globals.converter._dispatch('paragraphs.after', text, options); return globals.converter._dispatch('paragraphs.after', text, options, globals);
}); });

View File

@ -5,7 +5,7 @@
showdown.subParser('spanGamut', function (text, options, globals) { showdown.subParser('spanGamut', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('spanGamut.before', text, options); text = globals.converter._dispatch('spanGamut.before', text, options, globals);
text = showdown.subParser('codeSpans')(text, options, globals); text = showdown.subParser('codeSpans')(text, options, globals);
text = showdown.subParser('escapeSpecialCharsWithinTagAttributes')(text, options, globals); text = showdown.subParser('escapeSpecialCharsWithinTagAttributes')(text, options, globals);
text = showdown.subParser('encodeBackslashEscapes')(text, options, globals); text = showdown.subParser('encodeBackslashEscapes')(text, options, globals);
@ -26,6 +26,6 @@ showdown.subParser('spanGamut', function (text, options, globals) {
// Do hard breaks: // Do hard breaks:
text = text.replace(/ +\n/g, ' <br />\n'); text = text.replace(/ +\n/g, ' <br />\n');
text = globals.converter._dispatch('spanGamut.after', text, options); text = globals.converter._dispatch('spanGamut.after', text, options, globals);
return text; return text;
}); });

View File

@ -2,9 +2,9 @@ showdown.subParser('strikethrough', function (text, options, globals) {
'use strict'; 'use strict';
if (options.strikethrough) { if (options.strikethrough) {
text = globals.converter._dispatch('strikethrough.before', text, options); text = globals.converter._dispatch('strikethrough.before', text, options, globals);
text = text.replace(/(?:~T){2}([\s\S]+?)(?:~T){2}/g, '<del>$1</del>'); text = text.replace(/(?:~T){2}([\s\S]+?)(?:~T){2}/g, '<del>$1</del>');
text = globals.converter._dispatch('strikethrough.after', text, options); text = globals.converter._dispatch('strikethrough.after', text, options, globals);
} }
return text; return text;

View File

@ -55,7 +55,7 @@ showdown.subParser('tables', function (text, options, globals) {
return tb; return tb;
} }
text = globals.converter._dispatch('tables.before', text, options); text = globals.converter._dispatch('tables.before', text, options, globals);
text = text.replace(tableRgx, function (rawTable) { text = text.replace(tableRgx, function (rawTable) {
@ -123,7 +123,7 @@ showdown.subParser('tables', function (text, options, globals) {
return buildTable(headers, cells); return buildTable(headers, cells);
}); });
text = globals.converter._dispatch('tables.after', text, options); text = globals.converter._dispatch('tables.after', text, options, globals);
return text; return text;
}); });