mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
af82c2b616
This feature allows users to define the image dimensions using markdown syntax: ``` ![my image](img.jpg =100x80 "image title") ``` To enable this feature, use the option `parseImgDimensions`. Closes #143
96 lines
2.6 KiB
JavaScript
96 lines
2.6 KiB
JavaScript
require('source-map-support').install();
|
|
require('chai').should();
|
|
var expect = require('chai').expect,
|
|
showdown = require('../../dist/showdown.js');
|
|
|
|
describe('showdown.options', function () {
|
|
'use strict';
|
|
|
|
describe('setOption() and getOption()', function () {
|
|
it('should set option foo=bar', function () {
|
|
showdown.setOption('foo', 'bar');
|
|
showdown.getOption('foo').should.equal('bar');
|
|
showdown.resetOptions();
|
|
expect(showdown.getOption('foo')).to.be.undefined();
|
|
});
|
|
});
|
|
|
|
describe('getDefaultOptions()', function () {
|
|
it('should get default options', function () {
|
|
var opts = {
|
|
omitExtraWLInCodeBlocks: false,
|
|
prefixHeaderId: false,
|
|
noHeaderId: false,
|
|
parseImgDimensions: false
|
|
};
|
|
expect(showdown.getDefaultOptions()).to.be.eql(opts);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('showdown.extension()', function () {
|
|
'use strict';
|
|
|
|
var extObjMock = {
|
|
type: 'lang',
|
|
filter: function () {}
|
|
},
|
|
extObjFunc = function () {
|
|
return extObjMock;
|
|
};
|
|
|
|
describe('should register', function () {
|
|
it('an extension object', function () {
|
|
showdown.extension('foo', extObjMock);
|
|
showdown.extension('foo').should.eql([extObjMock]);
|
|
showdown.resetExtensions();
|
|
});
|
|
|
|
it('an extension function', function () {
|
|
showdown.extension('foo', extObjFunc);
|
|
showdown.extension('foo').should.eql([extObjMock]);
|
|
showdown.resetExtensions();
|
|
});
|
|
});
|
|
|
|
describe('should refuse to register', function () {
|
|
it('a generic object', function () {
|
|
var fn = function () {
|
|
showdown.extension('foo', {});
|
|
};
|
|
expect(fn).to.throw();
|
|
});
|
|
|
|
it('an extension with invalid type', function () {
|
|
var fn = function () {
|
|
showdown.extension('foo', {
|
|
type: 'foo'
|
|
});
|
|
};
|
|
expect(fn).to.throw(/type .+? is not recognized\. Valid values: "lang" or "output"/);
|
|
});
|
|
|
|
it('an extension without regex or filter', function () {
|
|
var fn = function () {
|
|
showdown.extension('foo', {
|
|
type: 'lang'
|
|
});
|
|
};
|
|
expect(fn).to.throw(/extensions must define either a "regex" property or a "filter" method/);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('showdown.getAllExtensions()', function () {
|
|
'use strict';
|
|
var extObjMock = {
|
|
type: 'lang',
|
|
filter: function () {}
|
|
};
|
|
|
|
it('should return all extensions', function () {
|
|
showdown.extension('bar', extObjMock);
|
|
showdown.getAllExtensions().should.eql({bar: [extObjMock]});
|
|
});
|
|
});
|