2015-06-01 03:56:28 +08:00
|
|
|
/**
|
|
|
|
* Created by Estevao on 31-05-2015.
|
|
|
|
*/
|
2022-03-27 08:05:30 +08:00
|
|
|
chai.should();
|
|
|
|
|
2015-06-01 03:56:28 +08:00
|
|
|
|
|
|
|
describe('showdown.Converter', function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
describe('option methods', function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let converter = new showdown.Converter();
|
2015-06-01 03:56:28 +08:00
|
|
|
|
|
|
|
it('setOption() should set option foo=baz', function () {
|
|
|
|
converter.setOption('foo', 'baz');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('getOption() should get option foo to equal baz', function () {
|
|
|
|
converter.getOption('foo').should.equal('baz');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('getOptions() should contain foo=baz', function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let options = converter.getOptions();
|
2015-06-01 03:56:28 +08:00
|
|
|
options.should.have.ownProperty('foo');
|
|
|
|
options.foo.should.equal('baz');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-10 15:15:09 +08:00
|
|
|
describe('metadata methods', function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let converter = new showdown.Converter();
|
2017-12-10 15:15:09 +08:00
|
|
|
|
|
|
|
it('_setMetadataPair() should set foo to bar', function () {
|
|
|
|
converter._setMetadataPair('foo', 'bar');
|
|
|
|
converter.getMetadata().should.eql({foo: 'bar'});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('_setMetadata should set metadata to {baz: bazinga}', function () {
|
|
|
|
converter._setMetadataRaw('{baz: bazinga}');
|
|
|
|
converter.getMetadata(true).should.eql('{baz: bazinga}');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-09 03:09:12 +08:00
|
|
|
describe('converter.setFlavor()', function () {
|
2015-08-03 10:47:49 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test setFlavor('github')
|
|
|
|
*/
|
|
|
|
describe('github', function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let converter = new showdown.Converter(),
|
2017-01-09 03:09:12 +08:00
|
|
|
ghOpts = showdown.getFlavorOptions('github');
|
2015-07-12 09:15:35 +08:00
|
|
|
|
2015-08-03 10:47:49 +08:00
|
|
|
converter.setFlavor('github');
|
2015-07-12 09:15:35 +08:00
|
|
|
|
2022-03-27 08:05:30 +08:00
|
|
|
for (let opt in ghOpts) {
|
2015-08-03 10:47:49 +08:00
|
|
|
if (ghOpts.hasOwnProperty(opt)) {
|
|
|
|
check(opt, ghOpts[opt]);
|
|
|
|
}
|
2015-07-12 09:15:35 +08:00
|
|
|
}
|
2017-01-31 13:46:25 +08:00
|
|
|
function check (key, val) {
|
2022-03-27 08:05:30 +08:00
|
|
|
it('should set ' + key + ' to ' + val, function () {
|
2015-08-03 10:47:49 +08:00
|
|
|
converter.getOption(key).should.equal(val);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2015-07-12 09:15:35 +08:00
|
|
|
});
|
|
|
|
|
2017-01-09 03:09:12 +08:00
|
|
|
describe('getFlavor method', function () {
|
|
|
|
|
|
|
|
// reset showdown
|
|
|
|
showdown.setFlavor('vanilla');
|
|
|
|
|
|
|
|
describe('flavor', function () {
|
|
|
|
it('should be vanilla by default', function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let converter = new showdown.Converter();
|
2017-01-09 03:09:12 +08:00
|
|
|
converter.getFlavor().should.equal('vanilla');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be changed if global option is changed', function () {
|
|
|
|
showdown.setFlavor('github');
|
2022-03-27 08:05:30 +08:00
|
|
|
let converter = new showdown.Converter();
|
2017-01-09 03:09:12 +08:00
|
|
|
converter.getFlavor().should.equal('github');
|
|
|
|
showdown.setFlavor('vanilla');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not be changed if converter is initialized before global change', function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let converter = new showdown.Converter();
|
2017-01-09 03:09:12 +08:00
|
|
|
showdown.setFlavor('github');
|
|
|
|
converter.getFlavor().should.equal('vanilla');
|
|
|
|
showdown.setFlavor('vanilla');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-06-01 03:56:28 +08:00
|
|
|
describe('extension methods', function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let extObjMock = {
|
2015-06-01 03:56:28 +08:00
|
|
|
type: 'lang',
|
|
|
|
filter: function () {}
|
|
|
|
},
|
|
|
|
extObjFunc = function () {
|
|
|
|
return extObjMock;
|
|
|
|
};
|
|
|
|
|
|
|
|
it('addExtension() should add an extension Object', function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let converter = new showdown.Converter();
|
2015-06-01 03:56:28 +08:00
|
|
|
converter.addExtension(extObjMock);
|
|
|
|
converter.getAllExtensions().language.should.contain(extObjMock);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('addExtension() should unwrap an extension wrapped in a function', function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let converter = new showdown.Converter();
|
2015-06-01 03:56:28 +08:00
|
|
|
|
|
|
|
converter.addExtension(extObjFunc);
|
|
|
|
converter.getAllExtensions().language.should.contain(extObjMock);
|
|
|
|
});
|
|
|
|
|
2015-06-08 02:02:45 +08:00
|
|
|
it('useExtension() should use a previous registered extension in showdown', function () {
|
2015-06-01 03:56:28 +08:00
|
|
|
showdown.extension('foo', extObjMock);
|
2022-03-27 08:05:30 +08:00
|
|
|
let converter = new showdown.Converter();
|
2015-06-01 03:56:28 +08:00
|
|
|
|
2015-06-08 02:02:45 +08:00
|
|
|
converter.useExtension('foo');
|
2015-06-01 03:56:28 +08:00
|
|
|
converter.getAllExtensions().language.should.contain(extObjMock);
|
|
|
|
showdown.resetExtensions();
|
|
|
|
});
|
2018-12-16 00:02:14 +08:00
|
|
|
|
|
|
|
it('removeExtension() should remove an added extension', function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let converter = new showdown.Converter();
|
2018-12-16 00:02:14 +08:00
|
|
|
converter.addExtension(extObjMock);
|
|
|
|
|
|
|
|
converter.removeExtension(extObjMock);
|
|
|
|
converter.getAllExtensions().language.should.not.contain(extObjMock);
|
|
|
|
});
|
2015-06-01 03:56:28 +08:00
|
|
|
});
|
2015-08-03 10:47:49 +08:00
|
|
|
|
|
|
|
describe('events', function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let events = [
|
2018-09-14 21:10:15 +08:00
|
|
|
'makehtml.anchors',
|
|
|
|
'makehtml.autoLinks',
|
|
|
|
'makehtml.blockGamut',
|
|
|
|
'makehtml.blockQuotes',
|
|
|
|
'makehtml.codeBlocks',
|
|
|
|
'makehtml.codeSpans',
|
|
|
|
'makehtml.githubCodeBlocks',
|
|
|
|
'makehtml.headers',
|
|
|
|
'makehtml.images',
|
|
|
|
'makehtml.italicsAndBold',
|
|
|
|
'makehtml.lists',
|
|
|
|
'makehtml.paragraph',
|
|
|
|
'makehtml.spanGamut'
|
2017-01-31 13:46:25 +08:00
|
|
|
//'strikeThrough',
|
|
|
|
//'tables'
|
|
|
|
];
|
2015-08-03 10:47:49 +08:00
|
|
|
|
2022-03-27 08:05:30 +08:00
|
|
|
for (let i = 0; i < events.length; ++i) {
|
2015-08-03 10:47:49 +08:00
|
|
|
runListener(events[i] + '.before');
|
|
|
|
runListener(events[i] + '.after');
|
|
|
|
}
|
|
|
|
|
|
|
|
function runListener (name) {
|
|
|
|
it('should listen to ' + name, function () {
|
2022-03-27 08:05:30 +08:00
|
|
|
let converter = new showdown.Converter();
|
2018-09-14 21:10:15 +08:00
|
|
|
converter.listen(name, function (event) {
|
2022-03-31 12:00:21 +08:00
|
|
|
let evtName = event.name;
|
|
|
|
let text = event.input;
|
2018-09-14 21:10:15 +08:00
|
|
|
evtName.should.equal(name.toLowerCase());
|
2015-08-03 10:47:49 +08:00
|
|
|
text.should.match(/^[\s\S]*foo[\s\S]*$/);
|
|
|
|
return text;
|
|
|
|
})
|
|
|
|
.makeHtml('foo');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2015-06-01 03:56:28 +08:00
|
|
|
});
|