diff --git a/Gruntfile.js b/Gruntfile.js index 1cc7853..5fccc49 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -33,6 +33,7 @@ module.exports = function (grunt) { 'src/options.js', 'src/showdown.js', 'src/helpers.js', + 'src/event.js', 'src/subParsers/makehtml/*.js', 'src/subParsers/makemarkdown/*.js', 'src/converter.js', diff --git a/src/converter.js b/src/converter.js index 70fc1d6..d5266a9 100644 --- a/src/converter.js +++ b/src/converter.js @@ -214,12 +214,12 @@ showdown.Converter = function (converterOptions) { /** * - * @param {showdown.helper.Event} event - * @returns showdown.helper.Event + * @param {showdown.Event} event + * @returns showdown.Event */ this.dispatch = function (event) { - if (!(event instanceof showdown.helper.Event)) { - throw new TypeError('dispatch only accepts showdown.helper.Event objects as param, but ' + typeof event + ' given'); + if (!(event instanceof showdown.Event)) { + throw new TypeError('dispatch only accepts showdown.Event objects as param, but ' + typeof event + ' given'); } event.converter = this; if (listeners.hasOwnProperty(event.name)) { @@ -228,7 +228,7 @@ showdown.Converter = function (converterOptions) { if (showdown.helper.isString(listRet)) { event.output = listRet; event.input = listRet; - } else if (listRet instanceof showdown.helper.Event && listRet.name === event.name) { + } else if (listRet instanceof showdown.Event && listRet.name === event.name) { event = listRet; } } @@ -243,7 +243,7 @@ showdown.Converter = function (converterOptions) { * @param {{}} options Converter Options * @param {{}} globals Converter globals * @param {{}} [pParams] extra params for event - * @returns showdown.helper.Event + * @returns showdown.Event * @private */ this._dispatch = function dispatch (evtName, text, options, globals, pParams) { @@ -254,7 +254,7 @@ showdown.Converter = function (converterOptions) { params.input = text; params.options = options; params.globals = globals; - var event = new showdown.helper.Event(evtName, text, params); + var event = new showdown.Event(evtName, text, params); if (listeners.hasOwnProperty(evtName)) { for (var ei = 0; ei < listeners[evtName].length; ++ei) { diff --git a/src/event.js b/src/event.js new file mode 100644 index 0000000..7c36b7d --- /dev/null +++ b/src/event.js @@ -0,0 +1,228 @@ +/** + * Created by Estevao on 31-05-2015. + */ + +/** + * @type {showdown.Event} + */ +showdown.Event = class { + + /** + * Creates a new showdown Event object + * @param {string} name + * @param {string} input + * @param {{}} [params] + * @param {string} params.output + * @param {RegExp} params.regexp + * @param {{}} params.matches + * @param {{}} params.attributes + * @param {{}} params.globals + * @param {{}} params.options + * @param {showdown.Converter} params.converter + */ + constructor (name, input, params) { + params = params || {}; + let {output, regexp, matches, attributes, globals, options, converter} = params; + if (!showdown.helper.isString(name)) { + if (!showdown.helper.isString(name)) { + throw new TypeError('Event.name must be a string but ' + typeof name + ' given'); + } + } + this._name = name.toLowerCase(); + this.input = input; + this.output = output || input; + this.regexp = regexp || null; + this.matches = matches || {}; + this.attributes = attributes || {}; + this._globals = globals || {}; + this._options = showdown.helper.cloneObject(options, true) || {}; + this._converter = converter || undefined; + } + + /** @returns {string} */ + get name () { + return this._name; + } + + /** @returns {string} */ + get input () { + return this._input; + } + + /** @param {string} value */ + set input (value) { + if (!showdown.helper.isString(value)) { + throw new TypeError('Event.input must be a string but ' + typeof value + ' given'); + } + this._input = value; + } + + /** @returns {string} */ + get output () { + return this._output; + } + + /** @param {string|null} value */ + set output (value) { + if (!showdown.helper.isString(value) && value !== null) { + throw new TypeError('Event.output must be a string but ' + typeof value + ' given'); + } + this._output = value; + } + + /** @returns {null|RegExp} */ + get regexp () { + return this._regexp; + } + + /** @param {null|RegExp} value */ + set regexp (value) { + if (!(value instanceof RegExp) && value !== null) { + throw new TypeError('Event.regexp must be a RegExp object (or null) but ' + typeof value + ' given'); + } + this._regexp = value; + } + + /** @returns {{}} */ + get matches () { + return this._matches; + } + + /** @param {{}}value */ + set matches (value) { + if (typeof value !== 'object') { + throw new TypeError('Event.matches must be an object (or null) but ' + typeof value + ' given'); + } + this._matches = {}; + for (let prop in value) { + if (value.hasOwnProperty(prop)) { + let descriptor = {}; + if (/^_(.+)/.test(prop)) { + descriptor = { + enumerable: true, + configurable: false, + writable: false, + value: value[prop] + }; + } else { + descriptor = { + enumerable: true, + configurable: false, + writable: true, + value: value[prop] + }; + } + Object.defineProperty(this._matches, prop, descriptor); + } + } + } + + /** @returns {{}} */ + get attributes () { + return this._attributes; + } + + /** @param {{}} value */ + set attributes (value) { + if (typeof value !== 'object') { + throw new TypeError('Event.attributes must be an object (or null) but ' + typeof value + ' given'); + } + this._attributes = value; + } + + /** @param {showdown.Converter} converter */ + set converter (converter) { + this._converter = converter; + } + + /** @returns {showdown.Converter} */ + get converter () { + return this._converter; + } + + get options () { + return this._options; + } + + get globals () { + return this._globals; + } + // FLUID INTERFACE + + /** + * + * @param {string} value + * @returns {showdown.Event} + */ + setInput (value) { + this.input = value; + return this; + } + + /** + * + * @param {string|null} value + * @returns {showdown.Event} + */ + setOutput (value) { + this.output = value; + return this; + } + + /** + * + * @param {RegExp} value + * @returns {showdown.Event} + */ + setRegexp (value) { + this.regexp = value; + return this; + } + + /** + * + * @param {{}}value + * @returns {showdown.Event} + */ + setMatches (value) { + this.matches = value; + return this; + } + + /** + * + * @param {{}}value + * @returns {showdown.Event} + */ + setAttributes (value) { + this.attributes = value; + return this; + } + + _setOptions (value) { + this._options = value; + return this; + } + + _setGlobals (value) { + this._globals = value; + return this; + } + + _setConverter (value) { + this.converter = value; + return this; + } + + /** + * Legacy: Return the output text + * @returns {string} + */ + getText () { + return this.output; + } + + getMatches () { + return this.matches; + } +}; diff --git a/src/helpers.js b/src/helpers.js index 3d2ec39..4054e39 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -57,7 +57,15 @@ showdown.helper.isFunction = function (a) { */ showdown.helper.isArray = function (a) { 'use strict'; - return Array.isArray(a); + let isArray; + if (!Array.isArray) { + isArray = function (arg) { + return Object.prototype.toString.call(arg) === '[object Array]'; + }; + } else { + isArray = Array.isArray; + } + return isArray(a); }; /** @@ -125,7 +133,7 @@ showdown.helper.forEach = function (obj, callback) { }; /** - * Standardidize extension name + * Standardize extension name * @static * @param {string} s extension name * @returns {string} @@ -718,228 +726,6 @@ showdown.helper.validateOptions = function (options) { return options; }; -showdown.helper.Event = class { - - /** - * Creates a new event object - * @param {string} name - * @param {string} input - * @param {{}} [params] - * @param {string} params.output - * @param {RegExp} params.regexp - * @param {{}} params.matches - * @param {{}} params.attributes - * @param {{}} params.globals - * @param {{}} params.options - * @param {showdown.Converter} params.converter - */ - constructor (name, input, params) { - params = params || {}; - let {output, regexp, matches, attributes, globals, options, converter} = params; - if (!showdown.helper.isString(name)) { - if (!showdown.helper.isString(name)) { - throw new TypeError('Event.name must be a string but ' + typeof name + ' given'); - } - } - this._name = name.toLowerCase(); - this.input = input; - this.output = output || input; - this.regexp = regexp || null; - this.matches = matches || {}; - this.attributes = attributes || {}; - this._globals = globals || {}; - this._options = showdown.helper.cloneObject(options, true) || {}; - this._converter = converter || undefined; - } - - /** @returns {string} */ - get name () { - return this._name; - } - - /** @returns {string} */ - get input () { - return this._input; - } - - /** @param {string} value */ - set input (value) { - if (!showdown.helper.isString(value)) { - throw new TypeError('Event.input must be a string but ' + typeof value + ' given'); - } - this._input = value; - } - - /** @returns {string} */ - get output () { - return this._output; - } - - /** @param {string|null} value */ - set output (value) { - if (!showdown.helper.isString(value) && value !== null) { - throw new TypeError('Event.output must be a string but ' + typeof value + ' given'); - } - this._output = value; - } - - /** @returns {null|RegExp} */ - get regexp () { - return this._regexp; - } - - /** @param {null|RegExp} value */ - set regexp (value) { - if (!(value instanceof RegExp) && value !== null) { - throw new TypeError('Event.regexp must be a RegExp object (or null) but ' + typeof value + ' given'); - } - this._regexp = value; - } - - /** @returns {{}} */ - get matches () { - return this._matches; - } - - /** @param {{}}value */ - set matches (value) { - if (typeof value !== 'object') { - throw new TypeError('Event.matches must be an object (or null) but ' + typeof value + ' given'); - } - this._matches = {}; - for (let prop in value) { - if (value.hasOwnProperty(prop)) { - let descriptor = {}; - if (/^_(.+)/.test(prop)) { - descriptor = { - enumerable: true, - configurable: false, - writable: false, - value: value[prop] - }; - } else { - descriptor = { - enumerable: true, - configurable: false, - writable: true, - value: value[prop] - }; - } - Object.defineProperty(this._matches, prop, descriptor); - } - } - } - - /** @returns {{}} */ - get attributes () { - return this._attributes; - } - - /** @param {{}} value */ - set attributes (value) { - if (typeof value !== 'object') { - throw new TypeError('Event.attributes must be an object (or null) but ' + typeof value + ' given'); - } - this._attributes = value; - } - - /** @param {showdown.Converter} converter */ - set converter (converter) { - this._converter = converter; - } - - /** @returns {showdown.Converter} */ - get converter () { - return this._converter; - } - - get options () { - return this._options; - } - - get globals () { - return this._globals; - } - // FLUID INTERFACE - - /** - * - * @param {string} value - * @returns {showdown.helper.Event} - */ - setInput (value) { - this.input = value; - return this; - } - - /** - * - * @param {string|null} value - * @returns {showdown.helper.Event} - */ - setOutput (value) { - this.output = value; - return this; - } - - /** - * - * @param {RegExp} value - * @returns {showdown.helper.Event} - */ - setRegexp (value) { - this.regexp = value; - return this; - } - - /** - * - * @param {{}}value - * @returns {showdown.helper.Event} - */ - setMatches (value) { - this.matches = value; - return this; - } - - /** - * - * @param {{}}value - * @returns {showdown.helper.Event} - */ - setAttributes (value) { - this.attributes = value; - return this; - } - - _setOptions (value) { - this._options = value; - return this; - } - - _setGlobals (value) { - this._globals = value; - return this; - } - - _setConverter (value) { - this.converter = value; - return this; - } - - /** - * Legacy: Return the output text - * @returns {string} - */ - getText () { - return this.output; - } - - getMatches () { - return this.matches; - } -}; - /** * POLYFILLS */ diff --git a/src/subParsers/makehtml/blockGamut.js b/src/subParsers/makehtml/blockGamut.js index 97ead7d..f2b18a4 100644 --- a/src/subParsers/makehtml/blockGamut.js +++ b/src/subParsers/makehtml/blockGamut.js @@ -13,7 +13,7 @@ showdown.subParser('makehtml.blockGamut', function (text, options, globals) { 'use strict'; - let startEvent = new showdown.helper.Event('makehtml.blockGamut.onStart', text); + let startEvent = new showdown.Event('makehtml.blockGamut.onStart', text); startEvent .setOutput(text) ._setGlobals(globals) @@ -40,7 +40,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); - let afterEvent = new showdown.helper.Event('makehtml.blockGamut.onEnd', text); + let afterEvent = new showdown.Event('makehtml.blockGamut.onEnd', text); afterEvent .setOutput(text) ._setGlobals(globals) diff --git a/src/subParsers/makehtml/blockquote.js b/src/subParsers/makehtml/blockquote.js index e777960..4f71133 100644 --- a/src/subParsers/makehtml/blockquote.js +++ b/src/subParsers/makehtml/blockquote.js @@ -16,7 +16,7 @@ showdown.subParser('makehtml.blockquote', function (text, options, globals) { 'use strict'; - let startEvent = new showdown.helper.Event('makehtml.blockquote.onStart', text); + let startEvent = new showdown.Event('makehtml.blockquote.onStart', text); startEvent .setOutput(text) ._setGlobals(globals) @@ -44,7 +44,7 @@ showdown.subParser('makehtml.blockquote', function (text, options, globals) { bq = bq.replace(/¨0/g, ''); bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines - let captureStartEvent = new showdown.helper.Event('makehtml.blockquote.onCapture', bq); + let captureStartEvent = new showdown.Event('makehtml.blockquote.onCapture', bq); captureStartEvent .setOutput(null) ._setGlobals(globals) @@ -74,7 +74,7 @@ showdown.subParser('makehtml.blockquote', function (text, options, globals) { otp = '
\n' + bq + '\n'; } - let beforeHashEvent = new showdown.helper.Event('makehtml.blockquote.onHash', otp); + let beforeHashEvent = new showdown.Event('makehtml.blockquote.onHash', otp); beforeHashEvent .setOutput(otp) ._setGlobals(globals) @@ -84,7 +84,7 @@ showdown.subParser('makehtml.blockquote', function (text, options, globals) { return showdown.subParser('makehtml.hashBlock')(otp, options, globals); }); - let afterEvent = new showdown.helper.Event('makehtml.blockquote.onEnd', text); + let afterEvent = new showdown.Event('makehtml.blockquote.onEnd', text); afterEvent .setOutput(text) ._setGlobals(globals) diff --git a/src/subParsers/makehtml/codeBlock.js b/src/subParsers/makehtml/codeBlock.js index 9cf4d32..90aacb6 100644 --- a/src/subParsers/makehtml/codeBlock.js +++ b/src/subParsers/makehtml/codeBlock.js @@ -12,7 +12,7 @@ showdown.subParser('makehtml.codeBlock', function (text, options, globals) { 'use strict'; - let startEvent = new showdown.helper.Event('makehtml.codeBlock.onStart', text); + let startEvent = new showdown.Event('makehtml.codeBlock.onStart', text); startEvent .setOutput(text) ._setGlobals(globals) @@ -34,7 +34,7 @@ showdown.subParser('makehtml.codeBlock', function (text, options, globals) { code: {} }; - let captureStartEvent = new showdown.helper.Event('makehtml.codeBlock.onCapture', codeblock); + let captureStartEvent = new showdown.Event('makehtml.codeBlock.onCapture', codeblock); captureStartEvent .setOutput(null) ._setGlobals(globals) @@ -71,7 +71,7 @@ showdown.subParser('makehtml.codeBlock', function (text, options, globals) { otp += codeblock + end + ''; } - let beforeHashEvent = new showdown.helper.Event('makehtml.codeBlock.onHash', otp); + let beforeHashEvent = new showdown.Event('makehtml.codeBlock.onHash', otp); beforeHashEvent .setOutput(otp) ._setGlobals(globals) @@ -85,7 +85,7 @@ showdown.subParser('makehtml.codeBlock', function (text, options, globals) { // strip sentinel text = text.replace(/¨0/, ''); - let afterEvent = new showdown.helper.Event('makehtml.codeBlock.onEnd', text); + let afterEvent = new showdown.Event('makehtml.codeBlock.onEnd', text); afterEvent .setOutput(text) ._setGlobals(globals) diff --git a/src/subParsers/makehtml/codeSpan.js b/src/subParsers/makehtml/codeSpan.js index 79255a7..1c135a3 100644 --- a/src/subParsers/makehtml/codeSpan.js +++ b/src/subParsers/makehtml/codeSpan.js @@ -33,7 +33,7 @@ showdown.subParser('makehtml.codeSpan', function (text, options, globals) { 'use strict'; - let startEvent = new showdown.helper.Event('makehtml.codeSpan.onStart', text); + let startEvent = new showdown.Event('makehtml.codeSpan.onStart', text); startEvent .setOutput(text) ._setGlobals(globals) @@ -56,7 +56,7 @@ showdown.subParser('makehtml.codeSpan', function (text, options, globals) { c = c.replace(/^([ \t]*)/g, ''); // leading whitespace c = c.replace(/[ \t]*$/g, ''); // trailing whitespace - let captureStartEvent = new showdown.helper.Event('makehtml.codeSpan.onCapture', c); + let captureStartEvent = new showdown.Event('makehtml.codeSpan.onCapture', c); captureStartEvent .setOutput(null) ._setGlobals(globals) @@ -79,7 +79,7 @@ showdown.subParser('makehtml.codeSpan', function (text, options, globals) { otp = m1 + '
' + c + '
';
}
- let beforeHashEvent = new showdown.helper.Event('makehtml.codeSpan.onHash', otp);
+ let beforeHashEvent = new showdown.Event('makehtml.codeSpan.onHash', otp);
beforeHashEvent
.setOutput(otp)
._setGlobals(globals)
@@ -91,7 +91,7 @@ showdown.subParser('makehtml.codeSpan', function (text, options, globals) {
}
);
- let afterEvent = new showdown.helper.Event('makehtml.codeSpan.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.codeSpan.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/completeHTMLDocument.js b/src/subParsers/makehtml/completeHTMLDocument.js
index 76db67f..4f7db4d 100644
--- a/src/subParsers/makehtml/completeHTMLDocument.js
+++ b/src/subParsers/makehtml/completeHTMLDocument.js
@@ -16,7 +16,7 @@ showdown.subParser('makehtml.completeHTMLDocument', function (text, options, glo
return text;
}
- let startEvent = new showdown.helper.Event('makehtml.completeHTMLDocument.onStart', text);
+ let startEvent = new showdown.Event('makehtml.completeHTMLDocument.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -71,7 +71,7 @@ showdown.subParser('makehtml.completeHTMLDocument', function (text, options, glo
text = doctypeParsed + '\n\n' + title + charset + metadata + '\n\n' + text.trim() + '\n\n';
- let afterEvent = new showdown.helper.Event('makehtml.completeHTMLDocument.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.completeHTMLDocument.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/detab.js b/src/subParsers/makehtml/detab.js
index 5a53902..be16e37 100644
--- a/src/subParsers/makehtml/detab.js
+++ b/src/subParsers/makehtml/detab.js
@@ -12,7 +12,7 @@
showdown.subParser('makehtml.detab', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.detab.onStart', text);
+ let startEvent = new showdown.Event('makehtml.detab.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -43,7 +43,7 @@ showdown.subParser('makehtml.detab', function (text, options, globals) {
text = text.replace(/¨A/g, ' '); // g_tab_width
text = text.replace(/¨B/g, '');
- let afterEvent = new showdown.helper.Event('makehtml.detab.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.detab.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/ellipsis.js b/src/subParsers/makehtml/ellipsis.js
index 7d1d604..563d0b7 100644
--- a/src/subParsers/makehtml/ellipsis.js
+++ b/src/subParsers/makehtml/ellipsis.js
@@ -16,7 +16,7 @@ showdown.subParser('makehtml.ellipsis', function (text, options, globals) {
return text;
}
- let startEvent = new showdown.helper.Event('makehtml.ellipsis.onStart', text);
+ let startEvent = new showdown.Event('makehtml.ellipsis.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -26,7 +26,7 @@ showdown.subParser('makehtml.ellipsis', function (text, options, globals) {
text = text.replace(/\.\.\./g, '…');
- let afterEvent = new showdown.helper.Event('makehtml.ellipsis.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.ellipsis.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/emoji.js b/src/subParsers/makehtml/emoji.js
index 5eb7e2c..5ad80bf 100644
--- a/src/subParsers/makehtml/emoji.js
+++ b/src/subParsers/makehtml/emoji.js
@@ -17,7 +17,7 @@ showdown.subParser('makehtml.emoji', function (text, options, globals) {
return text;
}
- let startEvent = new showdown.helper.Event('makehtml.emoji.onStart', text);
+ let startEvent = new showdown.Event('makehtml.emoji.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -29,7 +29,7 @@ showdown.subParser('makehtml.emoji', function (text, options, globals) {
text = text.replace(pattern, function (wholeMatch, emojiCode) {
let otp = '';
- let captureStartEvent = new showdown.helper.Event('makehtml.emoji.onCapture', emojiCode);
+ let captureStartEvent = new showdown.Event('makehtml.emoji.onCapture', emojiCode);
captureStartEvent
.setOutput(null)
._setGlobals(globals)
@@ -51,7 +51,7 @@ showdown.subParser('makehtml.emoji', function (text, options, globals) {
otp = wm;
}
- let beforeHashEvent = new showdown.helper.Event('makehtml.emoji.onHash', otp);
+ let beforeHashEvent = new showdown.Event('makehtml.emoji.onHash', otp);
beforeHashEvent
.setOutput(otp)
._setGlobals(globals)
@@ -61,7 +61,7 @@ showdown.subParser('makehtml.emoji', function (text, options, globals) {
return beforeHashEvent.output;
});
- let afterEvent = new showdown.helper.Event('makehtml.emoji.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.emoji.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/emphasisAndStrong.js b/src/subParsers/makehtml/emphasisAndStrong.js
index 1cfd1d7..082152e 100644
--- a/src/subParsers/makehtml/emphasisAndStrong.js
+++ b/src/subParsers/makehtml/emphasisAndStrong.js
@@ -15,7 +15,7 @@
showdown.subParser('makehtml.emphasisAndStrong', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.emphasisAndStrong.onStart', text);
+ let startEvent = new showdown.Event('makehtml.emphasisAndStrong.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -61,7 +61,7 @@ showdown.subParser('makehtml.emphasisAndStrong', function (text, options, global
break;
}
- let captureStartEvent = new showdown.helper.Event('makehtml.' + subEventName + '.onCapture', txt);
+ let captureStartEvent = new showdown.Event('makehtml.' + subEventName + '.onCapture', txt);
captureStartEvent
.setOutput(null)
._setGlobals(globals)
@@ -102,7 +102,7 @@ showdown.subParser('makehtml.emphasisAndStrong', function (text, options, global
}
}
- let beforeHashEvent = new showdown.helper.Event('makehtml.' + subEventName + '.onHash', otp);
+ let beforeHashEvent = new showdown.Event('makehtml.' + subEventName + '.onHash', otp);
beforeHashEvent
.setOutput(otp)
._setGlobals(globals)
@@ -163,7 +163,7 @@ showdown.subParser('makehtml.emphasisAndStrong', function (text, options, global
return (/\S$/.test(m)) ? parseInside (m, '', wm, asteriskEm) : wm;
});
//}
- let afterEvent = new showdown.helper.Event('makehtml.emphasisAndStrong.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.emphasisAndStrong.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/encodeAmpsAndAngles.js b/src/subParsers/makehtml/encodeAmpsAndAngles.js
index fbb8a53..58da712 100644
--- a/src/subParsers/makehtml/encodeAmpsAndAngles.js
+++ b/src/subParsers/makehtml/encodeAmpsAndAngles.js
@@ -12,7 +12,7 @@
showdown.subParser('makehtml.encodeAmpsAndAngles', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.encodeAmpsAndAngles.onStart', text);
+ let startEvent = new showdown.Event('makehtml.encodeAmpsAndAngles.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -33,7 +33,7 @@ showdown.subParser('makehtml.encodeAmpsAndAngles', function (text, options, glob
// Encode >
text = text.replace(/>/g, '>');
- let afterEvent = new showdown.helper.Event('makehtml.encodeAmpsAndAngles.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.encodeAmpsAndAngles.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/encodeBackslashEscapes.js b/src/subParsers/makehtml/encodeBackslashEscapes.js
index d8d3a77..f6e39ab 100644
--- a/src/subParsers/makehtml/encodeBackslashEscapes.js
+++ b/src/subParsers/makehtml/encodeBackslashEscapes.js
@@ -21,7 +21,7 @@
showdown.subParser('makehtml.encodeBackslashEscapes', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.encodeBackslashEscapes.onStart', text);
+ let startEvent = new showdown.Event('makehtml.encodeBackslashEscapes.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -32,7 +32,7 @@ showdown.subParser('makehtml.encodeBackslashEscapes', function (text, options, g
text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
text = text.replace(/\\([`*_{}\[\]()>#+.!~=|:-])/g, showdown.helper.escapeCharactersCallback);
- let afterEvent = new showdown.helper.Event('makehtml.encodeBackslashEscapes.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.encodeBackslashEscapes.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/encodeCode.js b/src/subParsers/makehtml/encodeCode.js
index 8afe845..019e5f4 100644
--- a/src/subParsers/makehtml/encodeCode.js
+++ b/src/subParsers/makehtml/encodeCode.js
@@ -14,7 +14,7 @@
showdown.subParser('makehtml.encodeCode', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.encodeCode.onStart', text);
+ let startEvent = new showdown.Event('makehtml.encodeCode.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -32,7 +32,7 @@ showdown.subParser('makehtml.encodeCode', function (text, options, globals) {
// Now, escape characters that are magic in Markdown:
.replace(/([*_{}\[\]\\=~-])/g, showdown.helper.escapeCharactersCallback);
- let afterEvent = new showdown.helper.Event('makehtml.encodeCode.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.encodeCode.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js b/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js
index 9d33a87..e2447c4 100644
--- a/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js
+++ b/src/subParsers/makehtml/escapeSpecialCharsWithinTagAttributes.js
@@ -13,7 +13,7 @@
showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.escapeSpecialCharsWithinTagAttributes.onStart', text);
+ let startEvent = new showdown.Event('makehtml.escapeSpecialCharsWithinTagAttributes.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -36,7 +36,7 @@ showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes', function (t
.replace(/([\\`*_~=|])/g, showdown.helper.escapeCharactersCallback);
});
- let afterEvent = new showdown.helper.Event('makehtml.escapeSpecialCharsWithinTagAttributes.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.escapeSpecialCharsWithinTagAttributes.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/githubCodeBlock.js b/src/subParsers/makehtml/githubCodeBlock.js
index 5397d7a..7a98a66 100644
--- a/src/subParsers/makehtml/githubCodeBlock.js
+++ b/src/subParsers/makehtml/githubCodeBlock.js
@@ -24,7 +24,7 @@ showdown.subParser('makehtml.githubCodeBlock', function (text, options, globals)
return text;
}
- let startEvent = new showdown.helper.Event('makehtml.githubCodeBlock.onStart', text);
+ let startEvent = new showdown.Event('makehtml.githubCodeBlock.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -42,7 +42,7 @@ showdown.subParser('makehtml.githubCodeBlock', function (text, options, globals)
code: {},
};
- let captureStartEvent = new showdown.helper.Event('makehtml.githubCodeBlock.onCapture', codeblock);
+ let captureStartEvent = new showdown.Event('makehtml.githubCodeBlock.onCapture', codeblock);
captureStartEvent
.setOutput(null)
._setGlobals(globals)
@@ -106,7 +106,7 @@ showdown.subParser('makehtml.githubCodeBlock', function (text, options, globals)
otp += codeblock + end + '';
}
- let beforeHashEvent = new showdown.helper.Event('makehtml.githubCodeBlock.onHash', otp);
+ let beforeHashEvent = new showdown.Event('makehtml.githubCodeBlock.onHash', otp);
beforeHashEvent
.setOutput(otp)
._setGlobals(globals)
@@ -124,7 +124,7 @@ showdown.subParser('makehtml.githubCodeBlock', function (text, options, globals)
// attacklab: strip sentinel
text = text.replace(/¨0/, '');
- let afterEvent = new showdown.helper.Event('makehtml.githubCodeBlock.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.githubCodeBlock.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/hashBlock.js b/src/subParsers/makehtml/hashBlock.js
index 2dc5760..29b8034 100644
--- a/src/subParsers/makehtml/hashBlock.js
+++ b/src/subParsers/makehtml/hashBlock.js
@@ -10,7 +10,7 @@
showdown.subParser('makehtml.hashBlock', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.hashBlock.onStart', text);
+ let startEvent = new showdown.Event('makehtml.hashBlock.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -21,7 +21,7 @@ showdown.subParser('makehtml.hashBlock', function (text, options, globals) {
text = text.replace(/(^\n+|\n+$)/g, '');
text = '\n\n¨K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n';
- let afterEvent = new showdown.helper.Event('makehtml.hashBlock.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.hashBlock.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/hashCodeTags.js b/src/subParsers/makehtml/hashCodeTags.js
index e71eafa..8ebb326 100644
--- a/src/subParsers/makehtml/hashCodeTags.js
+++ b/src/subParsers/makehtml/hashCodeTags.js
@@ -11,7 +11,7 @@
showdown.subParser('makehtml.hashCodeTags', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.hashCodeTags.onStart', text);
+ let startEvent = new showdown.Event('makehtml.hashCodeTags.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -27,7 +27,7 @@ showdown.subParser('makehtml.hashCodeTags', function (text, options, globals) {
// Hash naked
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, ']*>', '
', 'gim');
- let afterEvent = new showdown.helper.Event('makehtml.hashCodeTags.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.hashCodeTags.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/hashHTMLBlocks.js b/src/subParsers/makehtml/hashHTMLBlocks.js
index 63cc77a..98339fb 100644
--- a/src/subParsers/makehtml/hashHTMLBlocks.js
+++ b/src/subParsers/makehtml/hashHTMLBlocks.js
@@ -11,7 +11,7 @@
showdown.subParser('makehtml.hashHTMLBlocks', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.hashHTMLBlocks.onStart', text);
+ let startEvent = new showdown.Event('makehtml.hashHTMLBlocks.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -111,7 +111,7 @@ 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));
- let afterEvent = new showdown.helper.Event('makehtml.hashHTMLBlocks.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.hashHTMLBlocks.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/hashHTMLSpans.js b/src/subParsers/makehtml/hashHTMLSpans.js
index 96b51c5..0c06dde 100644
--- a/src/subParsers/makehtml/hashHTMLSpans.js
+++ b/src/subParsers/makehtml/hashHTMLSpans.js
@@ -11,7 +11,7 @@
showdown.subParser('makehtml.hashHTMLSpans', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.hashHTMLSpans.onStart', text);
+ let startEvent = new showdown.Event('makehtml.hashHTMLSpans.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -39,7 +39,7 @@ showdown.subParser('makehtml.hashHTMLSpans', function (text, options, globals) {
return showdown.helper._hashHTMLSpan(wm, globals);
});
- let afterEvent = new showdown.helper.Event('makehtml.hashHTMLSpans.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.hashHTMLSpans.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/hashPreCodeTags.js b/src/subParsers/makehtml/hashPreCodeTags.js
index c2b542a..fe5da8f 100644
--- a/src/subParsers/makehtml/hashPreCodeTags.js
+++ b/src/subParsers/makehtml/hashPreCodeTags.js
@@ -11,7 +11,7 @@
showdown.subParser('makehtml.hashPreCodeTags', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.hashHTMLBlocks.onStart', text);
+ let startEvent = new showdown.Event('makehtml.hashHTMLBlocks.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -28,7 +28,7 @@ showdown.subParser('makehtml.hashPreCodeTags', function (text, options, globals)
// Hash
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}]*>\\s*]*>', '^ {0,3}
\\s*
', 'gim');
- let afterEvent = new showdown.helper.Event('makehtml.hashPreCodeTags.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.hashPreCodeTags.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/heading.js b/src/subParsers/makehtml/heading.js
index a65ca7c..9ca040e 100644
--- a/src/subParsers/makehtml/heading.js
+++ b/src/subParsers/makehtml/heading.js
@@ -26,7 +26,7 @@ showdown.subParser('makehtml.heading', function (text, options, globals) {
'use strict';
function parseHeader (pattern, wholeMatch, headingText, headingLevel, headingId) {
- let captureStartEvent = new showdown.helper.Event('makehtml.heading.onCapture', headingText),
+ let captureStartEvent = new showdown.Event('makehtml.heading.onCapture', headingText),
otp;
captureStartEvent
@@ -54,7 +54,7 @@ showdown.subParser('makehtml.heading', function (text, options, globals) {
otp = '' + spanGamut + ' ';
}
- let beforeHashEvent = new showdown.helper.Event('makehtml.heading.onHash', otp);
+ let beforeHashEvent = new showdown.Event('makehtml.heading.onHash', otp);
beforeHashEvent
.setOutput(otp)
._setGlobals(globals)
@@ -65,7 +65,7 @@ showdown.subParser('makehtml.heading', function (text, options, globals) {
return showdown.subParser('makehtml.hashBlock')(otp, options, globals);
}
- let startEvent = new showdown.helper.Event('makehtml.heading.onStart', text);
+ let startEvent = new showdown.Event('makehtml.heading.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -95,7 +95,7 @@ showdown.subParser('makehtml.heading', function (text, options, globals) {
});
- let afterEvent = new showdown.helper.Event('makehtml.heading.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.heading.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/horizontalRule.js b/src/subParsers/makehtml/horizontalRule.js
index ecfca7e..1adec0d 100644
--- a/src/subParsers/makehtml/horizontalRule.js
+++ b/src/subParsers/makehtml/horizontalRule.js
@@ -12,7 +12,7 @@
////
showdown.subParser('makehtml.horizontalRule', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.horizontalRule.onStart', text);
+ let startEvent = new showdown.Event('makehtml.horizontalRule.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -25,7 +25,7 @@ showdown.subParser('makehtml.horizontalRule', function (text, options, globals)
text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
- let afterEvent = new showdown.helper.Event('makehtml.horizontalRule.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.horizontalRule.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/image.js b/src/subParsers/makehtml/image.js
index cfba5e5..db6d4cd 100644
--- a/src/subParsers/makehtml/image.js
+++ b/src/subParsers/makehtml/image.js
@@ -84,7 +84,7 @@ showdown.subParser('makehtml.image', function (text, options, globals) {
height = null;
}
- let captureStartEvent = new showdown.helper.Event('makehtml.image.onCapture', wholeMatch);
+ let captureStartEvent = new showdown.Event('makehtml.image.onCapture', wholeMatch);
captureStartEvent
.setOutput(null)
._setGlobals(globals)
@@ -109,7 +109,7 @@ showdown.subParser('makehtml.image', function (text, options, globals) {
otp = '';
}
- let beforeHashEvent = new showdown.helper.Event('makehtml.image.onHash', otp);
+ let beforeHashEvent = new showdown.Event('makehtml.image.onHash', otp);
beforeHashEvent
.setOutput(otp)
._setGlobals(globals)
@@ -120,7 +120,7 @@ showdown.subParser('makehtml.image', function (text, options, globals) {
return otp;
}
- let startEvent = new showdown.helper.Event('makehtml.image.onStart', text);
+ let startEvent = new showdown.Event('makehtml.image.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -163,7 +163,7 @@ showdown.subParser('makehtml.image', function (text, options, globals) {
return writeImageTag (refShortcutRegExp, wholeMatch, altText, '', '');
});
- let afterEvent = new showdown.helper.Event('makehtml.image.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.image.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/links.js b/src/subParsers/makehtml/links.js
index f3ae6f1..70c2a07 100644
--- a/src/subParsers/makehtml/links.js
+++ b/src/subParsers/makehtml/links.js
@@ -58,7 +58,7 @@
* @param {String} title
* @param {{}} options
* @param {{}} globals
- * @returns {showdown.helper.Event|*}
+ * @returns {showdown.Event|*}
*/
function createEvent (rgx, evtName, wholeMatch, text, id, url, title, options, globals) {
return globals.converter._dispatch(evtName, wholeMatch, options, globals, {
diff --git a/src/subParsers/makehtml/spanGamut.js b/src/subParsers/makehtml/spanGamut.js
index b4e2c1f..9a1a025 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';
- let startEvent = new showdown.helper.Event('makehtml.spanGamut.onStart', text);
+ let startEvent = new showdown.Event('makehtml.spanGamut.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -51,7 +51,7 @@ showdown.subParser('makehtml.spanGamut', function (text, options, globals) {
text = text.replace(/ +\n/g, '
\n');
}
- let afterEvent = new showdown.helper.Event('makehtml.spanGamut.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.spanGamut.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/unhashHTMLSpans.js b/src/subParsers/makehtml/unhashHTMLSpans.js
index 0f5fa95..3b61a88 100644
--- a/src/subParsers/makehtml/unhashHTMLSpans.js
+++ b/src/subParsers/makehtml/unhashHTMLSpans.js
@@ -11,7 +11,7 @@
showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals) {
'use strict';
- let startEvent = new showdown.helper.Event('makehtml.unhashHTMLSpans.onStart', text);
+ let startEvent = new showdown.Event('makehtml.unhashHTMLSpans.onStart', text);
startEvent
.setOutput(text)
._setGlobals(globals)
@@ -36,7 +36,7 @@ showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals)
text = text.replace('¨C' + i + 'C', repText);
}
- let afterEvent = new showdown.helper.Event('makehtml.unhashHTMLSpans.onEnd', text);
+ let afterEvent = new showdown.Event('makehtml.unhashHTMLSpans.onEnd', text);
afterEvent
.setOutput(text)
._setGlobals(globals)
diff --git a/test/unit/events.js b/test/unit/events.js
new file mode 100644
index 0000000..31b1186
--- /dev/null
+++ b/test/unit/events.js
@@ -0,0 +1,17 @@
+/**
+ * Created by Tivie on 04/03/2022.
+ */
+
+describe('showdown.Event', function () {
+ 'use strict';
+ let eventList = {
+
+ };
+ describe('event listeners', function () {
+
+ it('should listen to triggered event', function () {
+
+ })
+ });
+
+});
diff --git a/test/unit/showdown.js b/test/unit/showdown.js
index d96e9fc..97645a6 100644
--- a/test/unit/showdown.js
+++ b/test/unit/showdown.js
@@ -1,7 +1,6 @@
/**
* Created by Tivie on 27/01/2017.
*/
-//let showdown = require('../../.build/showdown.js') || require('showdown');
describe('showdown.options', function () {
'use strict';