diff --git a/karma.browserstack.js b/karma.browserstack.js
index 341e42c..a8daa51 100644
--- a/karma.browserstack.js
+++ b/karma.browserstack.js
@@ -70,6 +70,7 @@ module.exports = function (config) {
files: [
{ pattern: '.build/showdown.js'},
{ pattern: 'src/options.js'},
+ { pattern: 'test/mocks/md-to-trigger-all-events.ms', watched: false, included: false, served: true, nocache: false},
// tests
{ pattern: 'test/unit/showdown*.js' }
//{ pattern: 'test/functional/showdown*.js' },
diff --git a/karma.conf.js b/karma.conf.js
index ade836f..a3778f1 100644
--- a/karma.conf.js
+++ b/karma.conf.js
@@ -15,7 +15,8 @@ module.exports = function (config) {
{ pattern: 'src/options.js'},
// tests
{ pattern: 'test/unit/showdown*.js' },
- { pattern: 'test/functional/showdown*.js' },
+ { pattern: 'test/unit/showdown.events.js' },
+ //{ pattern: 'test/functional/makehtml/testsuite.*.js' },
],
reporters: ['progress'],
port: 9876, // karma web server port
diff --git a/src/converter.js b/src/converter.js
index d5266a9..b34a20b 100644
--- a/src/converter.js
+++ b/src/converter.js
@@ -11,7 +11,7 @@
showdown.Converter = function (converterOptions) {
'use strict';
- var
+ let
/**
* Options used by this converter
* @private
@@ -207,7 +207,7 @@ showdown.Converter = function (converterOptions) {
}
function rTrimInputText (text) {
- var rsp = text.match(/^\s*/)[0].length,
+ let rsp = text.match(/^\s*/)[0].length,
rgx = new RegExp('^\\s{0,' + rsp + '}', 'gm');
return text.replace(rgx, '');
}
@@ -236,37 +236,6 @@ showdown.Converter = function (converterOptions) {
return event;
};
- /**
- *
- * @param {string} evtName Event name
- * @param {string} text Text
- * @param {{}} options Converter Options
- * @param {{}} globals Converter globals
- * @param {{}} [pParams] extra params for event
- * @returns showdown.Event
- * @private
- */
- this._dispatch = function dispatch (evtName, text, options, globals, pParams) {
- evtName = evtName.toLowerCase();
- text = text || '';
- var params = pParams || {};
- params.converter = this;
- params.input = text;
- params.options = options;
- params.globals = globals;
- var event = new showdown.Event(evtName, text, params);
-
- if (listeners.hasOwnProperty(evtName)) {
- for (var ei = 0; ei < listeners[evtName].length; ++ei) {
- var nText = listeners[evtName][ei](event);
- if (nText && typeof nText !== 'undefined') {
- event.output = nText;
- }
- }
- }
- return event;
- };
-
/**
* Listen to an event
* @param {string} name
diff --git a/src/showdown.js b/src/showdown.js
index 76a6e68..a361b93 100644
--- a/src/showdown.js
+++ b/src/showdown.js
@@ -183,6 +183,14 @@ showdown.subParser = function (name, func) {
}
};
+/**
+ *
+ * @returns {{}}
+ */
+showdown.getSubParserList = function () {
+ return parsers;
+};
+
/**
* Gets or registers an extension
* @static
diff --git a/src/subParsers/makehtml/blockGamut.js b/src/subParsers/makehtml/blockGamut.js
index eb4eff6..2bb38d5 100644
--- a/src/subParsers/makehtml/blockGamut.js
+++ b/src/subParsers/makehtml/blockGamut.js
@@ -29,7 +29,7 @@ showdown.subParser('makehtml.blockGamut', function (text, options, globals) {
// Do Horizontal Rules:
text = showdown.subParser('makehtml.horizontalRule')(text, options, globals);
- text = showdown.subParser('makehtml.lists')(text, options, globals);
+ text = showdown.subParser('makehtml.list')(text, options, globals);
text = showdown.subParser('makehtml.codeBlock')(text, options, globals);
text = showdown.subParser('makehtml.table')(text, options, globals);
diff --git a/src/subParsers/makehtml/emoji.js b/src/subParsers/makehtml/emoji.js
index 5ad80bf..7a868a1 100644
--- a/src/subParsers/makehtml/emoji.js
+++ b/src/subParsers/makehtml/emoji.js
@@ -25,9 +25,12 @@ showdown.subParser('makehtml.emoji', function (text, options, globals) {
startEvent = globals.converter.dispatch(startEvent);
text = startEvent.output;
- let pattern = /:([\S]+?):/g;
+ let pattern = /:(\S+?):/g;
text = text.replace(pattern, function (wholeMatch, emojiCode) {
+ if (!showdown.helper.emojis.hasOwnProperty(emojiCode)) {
+ return wholeMatch;
+ }
let otp = '';
let captureStartEvent = new showdown.Event('makehtml.emoji.onCapture', emojiCode);
captureStartEvent
@@ -45,10 +48,8 @@ showdown.subParser('makehtml.emoji', function (text, options, globals) {
// if something was passed as output, it takes precedence and will be used as output
if (captureStartEvent.output && captureStartEvent.output !== '') {
otp = captureStartEvent.output;
- } else if (showdown.helper.emojis.hasOwnProperty(emojiCode)) {
- otp = showdown.helper.emojis[emojiCode];
} else {
- otp = wm;
+ otp = showdown.helper.emojis[emojiCode];
}
let beforeHashEvent = new showdown.Event('makehtml.emoji.onHash', otp);
diff --git a/src/subParsers/makehtml/emphasisAndStrong.js b/src/subParsers/makehtml/emphasisAndStrong.js
index bef8b02..73ceff5 100644
--- a/src/subParsers/makehtml/emphasisAndStrong.js
+++ b/src/subParsers/makehtml/emphasisAndStrong.js
@@ -102,7 +102,7 @@ showdown.subParser('makehtml.emphasisAndStrong', function (text, options, global
}
}
- let beforeHashEvent = new showdown.Event('makehtml.' + subEventName + '.onHash', otp);
+ let beforeHashEvent = new showdown.Event('makehtml.emphasisAndStrong.' + subEventName + '.onHash', otp);
beforeHashEvent
.setOutput(otp)
._setGlobals(globals)
diff --git a/src/subParsers/makehtml/horizontalRule.js b/src/subParsers/makehtml/horizontalRule.js
index 1adec0d..0c03087 100644
--- a/src/subParsers/makehtml/horizontalRule.js
+++ b/src/subParsers/makehtml/horizontalRule.js
@@ -20,10 +20,21 @@ showdown.subParser('makehtml.horizontalRule', function (text, options, globals)
startEvent = globals.converter.dispatch(startEvent);
text = startEvent.output;
- let 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);
+
+ const rgx1 = /^ {0,2}( ?-){3,}[ \t]*$/gm;
+ text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, function (wholeMatch) {
+ return parse(rgx1, wholeMatch);
+ });
+
+ const rgx2 = /^ {0,2}( ?\*){3,}[ \t]*$/gm;
+ text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, function (wholeMatch) {
+ return parse(rgx2, wholeMatch);
+ });
+
+ const rgx3 = /^ {0,2}( ?\*){3,}[ \t]*$/gm;
+ text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, function (wholeMatch) {
+ return parse(rgx3, wholeMatch);
+ });
let afterEvent = new showdown.Event('makehtml.horizontalRule.onEnd', text);
afterEvent
@@ -32,4 +43,44 @@ showdown.subParser('makehtml.horizontalRule', function (text, options, globals)
._setOptions(options);
afterEvent = globals.converter.dispatch(afterEvent);
return afterEvent.output;
+
+ /**
+ *
+ * @param {RegExp} pattern
+ * @param {string} wholeMatch
+ * @returns {string}
+ */
+ function parse (pattern, wholeMatch) {
+ let otp;
+ let captureStartEvent = new showdown.Event('makehtml.horizontalRule.onCapture', wholeMatch);
+ captureStartEvent
+ .setOutput(null)
+ ._setGlobals(globals)
+ ._setOptions(options)
+ .setRegexp(pattern)
+ .setMatches({
+ _whoteMatch: wholeMatch
+ })
+ .setAttributes({});
+ captureStartEvent = globals.converter.dispatch(captureStartEvent);
+
+ // if something was passed as output, it takes precedence
+ // and will be used as output
+ if (captureStartEvent.output && captureStartEvent.output !== '') {
+ otp = captureStartEvent.output;
+ } else {
+ otp = '
';
+ }
+
+ let beforeHashEvent = new showdown.Event('makehtml.horizontalRule.onHash', otp);
+ beforeHashEvent
+ .setOutput(otp)
+ ._setGlobals(globals)
+ ._setOptions(options);
+ beforeHashEvent = globals.converter.dispatch(beforeHashEvent);
+ otp = beforeHashEvent.output;
+ otp = showdown.subParser('makehtml.hashBlock')(otp, options, globals);
+ return otp;
+ }
+
});
diff --git a/src/subParsers/makehtml/image.js b/src/subParsers/makehtml/image.js
index d53d587..b596cd0 100644
--- a/src/subParsers/makehtml/image.js
+++ b/src/subParsers/makehtml/image.js
@@ -80,19 +80,19 @@ showdown.subParser('makehtml.image', function (text, options, globals) {
function writeImageTag (subEvtName, pattern, wholeMatch, altText, url, linkId, width, height, title) {
let gUrls = globals.gUrls,
- gTitles = globals.gTitles,
- gDims = globals.gDimensions,
- matches = {
- _wholeMatch: wholeMatch,
- _altText: altText,
- _linkId: linkId,
- _url: url,
- _width: width,
- _height: height,
- _title: title
- },
- otp,
- attributes = {};
+ gTitles = globals.gTitles,
+ gDims = globals.gDimensions,
+ matches = {
+ _wholeMatch: wholeMatch,
+ _altText: altText,
+ _linkId: linkId,
+ _url: url,
+ _width: width,
+ _height: height,
+ _title: title
+ },
+ otp,
+ attributes = {};
linkId = (linkId) ? linkId.toLowerCase() : null;
diff --git a/src/subParsers/makehtml/lists.js b/src/subParsers/makehtml/list.js
similarity index 98%
rename from src/subParsers/makehtml/lists.js
rename to src/subParsers/makehtml/list.js
index 1c8958d..6f11cb2 100644
--- a/src/subParsers/makehtml/lists.js
+++ b/src/subParsers/makehtml/list.js
@@ -1,5 +1,5 @@
////
-// makehtml/lists.js
+// makehtml/list.js
// Copyright (c) 2022 ShowdownJS
//
// Transforms MD lists into `` or `` html list
@@ -13,7 +13,7 @@
////
-showdown.subParser('makehtml.lists', function (text, options, globals) {
+showdown.subParser('makehtml.list', function (text, options, globals) {
'use strict';
// Start of list parsing
@@ -237,7 +237,7 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
item = showdown.subParser('makehtml.githubCodeBlock')(item, options, globals);
item = showdown.subParser('makehtml.blockquote')(item, options, globals);
item = showdown.subParser('makehtml.heading')(item, options, globals);
- item = showdown.subParser('makehtml.lists')(item, options, globals);
+ item = showdown.subParser('makehtml.list')(item, options, globals);
item = showdown.subParser('makehtml.codeBlock')(item, options, globals);
item = showdown.subParser('makehtml.table')(item, options, globals);
item = showdown.subParser('makehtml.hashHTMLBlocks')(item, options, globals);
@@ -279,7 +279,7 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
} else {
// Recursion for sub-lists:
- item = showdown.subParser('makehtml.lists')(item, options, globals);
+ item = showdown.subParser('makehtml.list')(item, options, globals);
item = item.replace(/\n$/, ''); // chomp(item)
item = showdown.subParser('makehtml.hashHTMLBlocks')(item, options, globals);
diff --git a/src/subParsers/makehtml/paragraphs.js b/src/subParsers/makehtml/paragraphs.js
index 77bb952..1792ff8 100644
--- a/src/subParsers/makehtml/paragraphs.js
+++ b/src/subParsers/makehtml/paragraphs.js
@@ -4,7 +4,6 @@
showdown.subParser('makehtml.paragraphs', function (text, options, globals) {
'use strict';
- 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 +65,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).getText();
+ return text;
});
diff --git a/src/subParsers/makehtml/underline.js b/src/subParsers/makehtml/underline.js
index 06ea727..d223474 100644
--- a/src/subParsers/makehtml/underline.js
+++ b/src/subParsers/makehtml/underline.js
@@ -46,9 +46,13 @@ 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).getText();
-
- return text;
+ let afterEvent = new showdown.Event('makehtml.underline.onEnd', text);
+ afterEvent
+ .setOutput(text)
+ ._setGlobals(globals)
+ ._setOptions(options);
+ afterEvent = globals.converter.dispatch(afterEvent);
+ return afterEvent.output;
function parse (pattern, wholeMatch, txt) {
diff --git a/test/bootstrap.js b/test/bootstrap.js
index 5c2ec14..6cc713c 100644
--- a/test/bootstrap.js
+++ b/test/bootstrap.js
@@ -1,6 +1,22 @@
//.webstorm.bootstrap.js
-var chai = require('chai');
+const chai = require('chai');
+const fs = require('fs');
global.chai = chai;
global.expect = chai.expect;
global.showdown = require('../.build/showdown.js');
global.getDefaultOpts = require('./optionswp.js').getDefaultOpts;
+
+// mock XMLHttpRequest for browser and node test
+function XMLHttpRequest () {
+ this.responseText = null;
+ this.status = null;
+
+ this.open = function (mode, file) {
+ //mode is ignored, it's always sync
+ this.responseText = fs.readFileSync(file);
+ this.status = 200;
+ return this;
+ };
+}
+
+global.XMLHttpRequest = XMLHttpRequest;
diff --git a/test/mocks/md-to-trigger-all-events.md b/test/mocks/md-to-trigger-all-events.md
new file mode 100644
index 0000000..3bb1178
--- /dev/null
+++ b/test/mocks/md-to-trigger-all-events.md
@@ -0,0 +1,82 @@
+# ATX h1
+
+## ATX h2
+
+### ATX h3
+
+#### ATX h4
+
+##### ATX h5
+
+###### ATX h6
+
+setext h1
+----------
+
+setext h2
+==========
+
+some paragraph
+
+*italic*
+
+**bold**
+
+***bold and italic***
+
+__underline__
+
+___superunderline___
+
+~~strikethrough~~
+
+[link](foo.com)
+
+|[img](foo.com/img.jpg)
+
+some `code line`
+
+---
+
+some http://autolink.com autolink
+
+> blockquote
+
+other paragraph
+
+ code
+ block
+
+```javascript
+gh codeblock
+```
+
+@mentions
+
+- ul 1
+- ul 2
+- ul 3
+
+other paragraph
+
+1. ol 1
+2. ol 2
+3. ol 3
+
+foo
+
+- [ ] task item 1
+- [X] task item 2
+
+| foo | bar |
+|-----|-----|
+| 1 | 2 |
+
+paragraph
+
+| foo | bar |
+|-----|-----|
+
+a div
+
+
diff --git a/test/optionswp.js b/test/optionswp.js
index dd20264..3c0d392 100644
--- a/test/optionswp.js
+++ b/test/optionswp.js
@@ -1,5 +1,5 @@
/* jshint ignore:start */
-var fs = require('fs'),
+let fs = require('fs'),
filedata;
filedata = fs.readFileSync('src/options.js', 'utf8');
eval(filedata);
diff --git a/test/unit/events.js b/test/unit/events.js
deleted file mode 100644
index 812c04d..0000000
--- a/test/unit/events.js
+++ /dev/null
@@ -1,15 +0,0 @@
-/**
- * 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.events.js b/test/unit/showdown.events.js
new file mode 100644
index 0000000..5dfb488
--- /dev/null
+++ b/test/unit/showdown.events.js
@@ -0,0 +1,293 @@
+/**
+ * Created by Tivie on 04/03/2022.
+ */
+
+// in node, if bootstrap is pre-loaded, there's a mock of XMLHttpRequest which
+// internally just calls fs.readFileSync
+
+describe('showdown.Event', function () {
+ 'use strict';
+ const subparserList = showdown.getSubParserList();
+ const eventTypes = [
+ 'onStart',
+ 'onEnd',
+ 'onCapture',
+ 'onHash'
+ ];
+
+ const testSpec = {
+ makehtml: {
+ doesNotExist: [
+ { event: 'onStart', text: 'foo', result: false },
+ { event: 'onEnd', text: 'foo', result: false },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ blockquote: [
+ { event: 'onStart', text: '> foo', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '> foo', result: true },
+ { event: 'onEnd', text: 'foo', result: true },
+ { event: 'onCapture', text: '> foo', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '> foo', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ codeBlock: [
+ { event: 'onStart', text: ' foo\n bar', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: ' foo\n bar', result: true },
+ { event: 'onEnd', text: 'foo', result: true },
+ { event: 'onCapture', text: ' foo\n bar', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: ' foo\n bar', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ codeSpan: [
+ { event: 'onStart', text: '`foo`', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '`foo`', result: true },
+ { event: 'onEnd', text: 'foo', result: true },
+ { event: 'onCapture', text: '`foo`', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '`foo`', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ emoji: [
+ { event: 'onStart', text: ':smile:', result: true },
+ { event: 'onStart', text: 'smile', result: true },
+ { event: 'onEnd', text: ':smile:', result: true },
+ { event: 'onEnd', text: 'smile', result: true },
+ { event: 'onCapture', text: ':smile:', result: true },
+ { event: 'onCapture', text: ':blablablablabla:', result: false }, // this emoji does not exist
+ { event: 'onCapture', text: 'smile', result: false },
+ { event: 'onHash', text: ':smile:', result: true },
+ { event: 'onHash', text: ':blablablablabla:', result: false }, // this emoji does not exist
+ { event: 'onHash', text: 'smile', result: false }
+ ],
+ emphasisAndStrong: [
+ { event: 'onStart', text: '*foo*', result: true },
+ { event: 'onStart', text: '**foo**', result: true },
+ { event: 'onStart', text: '***foo***', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '*foo*', result: true },
+ { event: 'onEnd', text: '**foo**', result: true },
+ { event: 'onEnd', text: '***foo***', result: true },
+ { event: 'onEnd', text: 'foo', result: true }
+ ],
+ 'emphasisAndStrong.emphasis': [
+ { event: 'onCapture', text: '*foo*', result: true },
+ { event: 'onCapture', text: '**foo**', result: false },
+ { event: 'onCapture', text: '***foo***', result: false },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '*foo*', result: true },
+ { event: 'onHash', text: '**foo**', result: false },
+ { event: 'onHash', text: '***foo***', result: false },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ 'emphasisAndStrong.strong': [
+ { event: 'onCapture', text: '*foo*', result: false },
+ { event: 'onCapture', text: '**foo**', result: true },
+ { event: 'onCapture', text: '***foo***', result: false },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '*foo*', result: false },
+ { event: 'onHash', text: '**foo**', result: true },
+ { event: 'onHash', text: '***foo***', result: false },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ 'emphasisAndStrong.emphasisAndStrong': [
+ { event: 'onCapture', text: '*foo*', result: false },
+ { event: 'onCapture', text: '**foo**', result: false },
+ { event: 'onCapture', text: '***foo***', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '*foo*', result: false },
+ { event: 'onHash', text: '**foo**', result: false },
+ { event: 'onHash', text: '***foo***', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ githubCodeBlock: [
+ { event: 'onStart', text: '```\nfoo\n```', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '```\nfoo\n```', result: true },
+ { event: 'onEnd', text: 'foo', result: true },
+ { event: 'onCapture', text: '```\nfoo\n```', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '```\nfoo\n```', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ heading: [
+ { event: 'onStart', text: '# foo', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '# foo', result: true },
+ { event: 'onEnd', text: 'foo', result: true },
+ { event: 'onCapture', text: '# foo', result: true },
+ { event: 'onCapture', text: 'foo\n---', result: true },
+ { event: 'onCapture', text: 'foo\n===', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '# foo', result: true },
+ { event: 'onHash', text: 'foo\n---', result: true },
+ { event: 'onHash', text: 'foo\n===', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ horizontalRule: [
+ { event: 'onStart', text: '---', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '---', result: true },
+ { event: 'onEnd', text: 'foo', result: true },
+ { event: 'onCapture', text: '---', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '---', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ image: [
+ { event: 'onStart', text: '![foo](bar.jpg)', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '![foo](bar.jpg)', result: true },
+ { event: 'onEnd', text: 'foo', result: true }
+ ],
+ 'image.inline': [
+ { event: 'onCapture', text: '![foo](bar.jpg)', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '![foo](bar.jpg)', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ 'image.reference': [
+ { event: 'onCapture', text: '![foo][1]\n\n[1]: bar.jpg', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '![foo][1]\n\n[1]: bar.jpg', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ link: [
+ { event: 'onStart', text: '[foo](bar.jpg)', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '[foo](bar.jpg)', result: true },
+ { event: 'onEnd', text: 'foo', result: true }
+ ],
+ 'link.inline': [
+ { event: 'onCapture', text: '[foo](bar.jpg)', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '[foo](bar.jpg)', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ 'link.reference': [
+ { event: 'onCapture', text: '[foo][1]\n\n[1]: bar.jpg', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '[foo][1]\n\n[1]: bar.jpg', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ list: [
+ { event: 'onStart', text: '1. foo\n2.bar\n', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '1. foo\n2.bar\n', result: true },
+ { event: 'onEnd', text: 'foo', result: true },
+ { event: 'onCapture', text: '1. foo\n2.bar\n', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ //{ event: 'onHash', text: '1. foo\n2.bar\n', result: true },
+ //{ event: 'onHash', text: 'foo', result: false }
+ ],
+ 'list.listItem': [
+ { event: 'onCapture', text: '1. foo\n2.bar\n', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '1. foo\n2.bar\n', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ 'list.taskListItem': [
+ { event: 'onCapture', text: '1. [X] foo\n2. [x] bar\n', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '1. [X] foo\n2. [x] bar\n', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ 'list.taskListItem.checkbox': [
+ { event: 'onCapture', text: '1. [X] foo\n2. [x] bar\n', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '1. [X] foo\n2. [x] bar\n', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ metadata: [
+ { event: 'onStart', text: '«««yaml\nfoo: bar\n»»»\n', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '«««yaml\nfoo: bar\n»»»\n', result: true },
+ { event: 'onEnd', text: 'foo', result: true },
+ { event: 'onCapture', text: '«««yaml\nfoo: bar\n»»»\n', result: true },
+ { event: 'onCapture', text: '---yaml\nfoo: bar\n---\n', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '«««yaml\nfoo: bar\n»»»\n', result: true },
+ { event: 'onHash', text: '---yaml\nfoo: bar\n---\n', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ strikethrough: [
+ { event: 'onStart', text: '~~foo~~', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '~~foo~~', result: true },
+ { event: 'onEnd', text: 'foo', result: true },
+ { event: 'onCapture', text: '~~foo~~', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '~~foo~~', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ table: [
+ { event: 'onStart', text: '|foo|bar|\n|---|---|\n|1|2|', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '|foo|bar|\n|---|---|\n|1|2|', result: true },
+ { event: 'onEnd', text: 'foo', result: true },
+ { event: 'onCapture', text: '|foo|bar|\n|---|---|\n|1|2|', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '|foo|bar|\n|---|---|\n|1|2|', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ],
+ underline: [
+ { event: 'onStart', text: '__foo__', result: true },
+ { event: 'onStart', text: 'foo', result: true },
+ { event: 'onEnd', text: '__foo__', result: true },
+ { event: 'onEnd', text: 'foo', result: true },
+ { event: 'onCapture', text: '__foo__', result: true },
+ { event: 'onCapture', text: 'foo', result: false },
+ { event: 'onHash', text: '__foo__', result: true },
+ { event: 'onHash', text: 'foo', result: false }
+ ]
+ }
+ };
+
+ describe('event triggering', function () {
+
+ let converter;
+
+ before(function () {
+ converter = new showdown.Converter({
+ strikethrough: true,
+ tables: true,
+ ghCodeBlocks: true,
+ tasklists: true,
+ ghMentions: true,
+ emoji: true,
+ underline: true,
+ ellipsis: true,
+ metadata: true
+ });
+ });
+
+ describe('makehtml', function () {
+ for (let parser in testSpec.makehtml) {
+
+ describe(parser, function () {
+ for (let ts in testSpec.makehtml[parser]) {
+ let event = 'makehtml.' + parser + '.' + testSpec.makehtml[parser][ts].event;
+ let md = testSpec.makehtml[parser][ts].text;
+ let title = (testSpec.makehtml[parser][ts].result) ? 'should ' : 'should NOT ';
+ title += 'trigger "' + event + ' event"';
+ let expected = testSpec.makehtml[parser][ts].result;
+ let actual = false;
+ it(title, function () {
+ converter.listen(event, function () {
+ actual = true;
+ });
+ converter.makeHtml(md);
+ expected.should.equal(actual);
+ });
+ }
+ });
+
+ }
+ });
+ });
+});