mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
add simple event trigger tests
This commit is contained in:
parent
47a340508e
commit
f9bc0ac97d
|
@ -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' },
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -183,6 +183,14 @@ showdown.subParser = function (name, func) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {{}}
|
||||
*/
|
||||
showdown.getSubParserList = function () {
|
||||
return parsers;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets or registers an extension
|
||||
* @static
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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')('<hr />', options, globals);
|
||||
text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key);
|
||||
text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
|
||||
text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
|
||||
|
||||
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 = '<hr' + showdown.helper._populateAttributes(captureStartEvent.attributes) + ' />';
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
////
|
||||
// makehtml/lists.js
|
||||
// makehtml/list.js
|
||||
// Copyright (c) 2022 ShowdownJS
|
||||
//
|
||||
// Transforms MD lists into `<ul>` or `<ol>` 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);
|
||||
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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) {
|
||||
|
|
18
test/bootstrap.js
vendored
18
test/bootstrap.js
vendored
|
@ -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;
|
||||
|
|
82
test/mocks/md-to-trigger-all-events.md
Normal file
82
test/mocks/md-to-trigger-all-events.md
Normal file
|
@ -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 |
|
||||
|-----|-----|
|
||||
|
||||
<div markdown="1">a div</div>
|
||||
|
||||
|
|
@ -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);
|
||||
|
|
|
@ -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 () {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
293
test/unit/showdown.events.js
Normal file
293
test/unit/showdown.events.js
Normal file
|
@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user