2015-01-16 05:21:33 +08:00
|
|
|
/**
|
|
|
|
* Created by Estevao on 15-01-2015.
|
|
|
|
*/
|
|
|
|
|
2015-06-01 01:47:09 +08:00
|
|
|
describe('showdown.Converter', function () {
|
2015-01-19 19:37:21 +08:00
|
|
|
'use strict';
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-01-19 19:37:21 +08:00
|
|
|
require('source-map-support').install();
|
|
|
|
require('chai').should();
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-07-12 02:32:22 +08:00
|
|
|
var showdown = require('../bootstrap').showdown;
|
2015-05-27 08:48:49 +08:00
|
|
|
|
2015-06-07 19:15:18 +08:00
|
|
|
describe('Converter.options extensions', function () {
|
2017-01-31 13:46:25 +08:00
|
|
|
var runCount;
|
2015-06-07 19:15:18 +08:00
|
|
|
showdown.extensions.testext = function () {
|
|
|
|
return [{
|
|
|
|
type: 'output',
|
|
|
|
filter: function (text) {
|
|
|
|
runCount = runCount + 1;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
};
|
2017-01-31 13:46:25 +08:00
|
|
|
|
|
|
|
var converter = new showdown.Converter({extensions: ['testext']});
|
2015-06-07 19:15:18 +08:00
|
|
|
|
|
|
|
it('output extensions should run once', function () {
|
|
|
|
runCount = 0;
|
|
|
|
converter.makeHtml('# testext');
|
|
|
|
runCount.should.equal(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-06-01 01:47:09 +08:00
|
|
|
describe('makeHtml() with option omitExtraWLInCodeBlocks', function () {
|
|
|
|
var converter = new showdown.Converter({omitExtraWLInCodeBlocks: true}),
|
2017-01-31 13:46:25 +08:00
|
|
|
text = 'var foo = bar;',
|
|
|
|
html = converter.makeHtml(' ' + text);
|
2015-06-01 01:47:09 +08:00
|
|
|
it('should omit extra line after code tag', function () {
|
|
|
|
var expectedHtml = '<pre><code>' + text + '</code></pre>';
|
|
|
|
html.should.equal(expectedHtml);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('makeHtml() with option prefixHeaderId', function () {
|
|
|
|
var converter = new showdown.Converter(),
|
2017-01-31 13:46:25 +08:00
|
|
|
text = 'foo header';
|
2015-06-01 01:47:09 +08:00
|
|
|
|
|
|
|
it('should prefix header id with "section"', function () {
|
|
|
|
converter.setOption('prefixHeaderId', true);
|
|
|
|
var html = converter.makeHtml('# ' + text),
|
2017-01-31 13:46:25 +08:00
|
|
|
expectedHtml = '<h1 id="sectionfooheader">' + text + '</h1>';
|
2015-06-01 01:47:09 +08:00
|
|
|
html.should.equal(expectedHtml);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should prefix header id with custom string', function () {
|
|
|
|
converter.setOption('prefixHeaderId', 'blabla');
|
|
|
|
var html = converter.makeHtml('# ' + text),
|
2017-01-31 13:46:25 +08:00
|
|
|
expectedHtml = '<h1 id="blablafooheader">' + text + '</h1>';
|
2015-06-01 01:47:09 +08:00
|
|
|
html.should.equal(expectedHtml);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|