mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
feat(flavours): add markdown presets/flavors
This feature enables users to select a preset/flavor. A flavor is just a preset of options, a shortcut so users don't have to set each option one by one. Closes #164
This commit is contained in:
parent
20ca099f56
commit
7e55bceb0e
49
dist/showdown.js
vendored
49
dist/showdown.js
vendored
@ -1,4 +1,4 @@
|
|||||||
;/*! showdown 11-07-2015 */
|
;/*! showdown 12-07-2015 */
|
||||||
(function(){
|
(function(){
|
||||||
/**
|
/**
|
||||||
* Created by Tivie on 06-01-2015.
|
* Created by Tivie on 06-01-2015.
|
||||||
@ -22,7 +22,21 @@ var showdown = {},
|
|||||||
ghCodeBlocks: true, // true due to historical reasons
|
ghCodeBlocks: true, // true due to historical reasons
|
||||||
tasklists: false
|
tasklists: false
|
||||||
},
|
},
|
||||||
globalOptions = JSON.parse(JSON.stringify(defaultOptions)); //clone default options out of laziness =P
|
globalOptions = JSON.parse(JSON.stringify(defaultOptions)),
|
||||||
|
flavor = {
|
||||||
|
github: {
|
||||||
|
omitExtraWLInCodeBlocks: true,
|
||||||
|
prefixHeaderId: 'user-content-',
|
||||||
|
simplifiedAutoLink: true,
|
||||||
|
literalMidWordUnderscores: true,
|
||||||
|
strikethrough: true,
|
||||||
|
tables: true,
|
||||||
|
tablesHeaderId: true,
|
||||||
|
ghCodeBlocks: true,
|
||||||
|
tasklists: true
|
||||||
|
},
|
||||||
|
vanilla: JSON.parse(JSON.stringify(defaultOptions))
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* helper namespace
|
* helper namespace
|
||||||
@ -79,6 +93,22 @@ showdown.resetOptions = function () {
|
|||||||
globalOptions = JSON.parse(JSON.stringify(defaultOptions));
|
globalOptions = JSON.parse(JSON.stringify(defaultOptions));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the flavor showdown should use as default
|
||||||
|
* @param {string} name
|
||||||
|
*/
|
||||||
|
showdown.setFlavor = function (name) {
|
||||||
|
'use strict';
|
||||||
|
if (flavor.hasOwnProperty(name)) {
|
||||||
|
var preset = flavor[name];
|
||||||
|
for (var option in preset) {
|
||||||
|
if (preset.hasOwnProperty(option)) {
|
||||||
|
globalOptions[option] = preset[option];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default options
|
* Get the default options
|
||||||
* @static
|
* @static
|
||||||
@ -701,6 +731,21 @@ showdown.Converter = function (converterOptions) {
|
|||||||
_parseExtension(extensionName);
|
_parseExtension(extensionName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the flavor THIS converter should use
|
||||||
|
* @param {string} name
|
||||||
|
*/
|
||||||
|
this.setFlavor = function (name) {
|
||||||
|
if (flavor.hasOwnProperty(name)) {
|
||||||
|
var preset = flavor[name];
|
||||||
|
for (var option in preset) {
|
||||||
|
if (preset.hasOwnProperty(option)) {
|
||||||
|
options[option] = preset[option];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an extension from THIS converter.
|
* Remove an extension from THIS converter.
|
||||||
* Note: This is a costly operation. It's better to initialize a new converter
|
* Note: This is a costly operation. It's better to initialize a new converter
|
||||||
|
2
dist/showdown.js.map
vendored
2
dist/showdown.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/showdown.min.js
vendored
4
dist/showdown.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/showdown.min.js.map
vendored
2
dist/showdown.min.js.map
vendored
File diff suppressed because one or more lines are too long
@ -285,6 +285,21 @@ showdown.Converter = function (converterOptions) {
|
|||||||
_parseExtension(extensionName);
|
_parseExtension(extensionName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the flavor THIS converter should use
|
||||||
|
* @param {string} name
|
||||||
|
*/
|
||||||
|
this.setFlavor = function (name) {
|
||||||
|
if (flavor.hasOwnProperty(name)) {
|
||||||
|
var preset = flavor[name];
|
||||||
|
for (var option in preset) {
|
||||||
|
if (preset.hasOwnProperty(option)) {
|
||||||
|
options[option] = preset[option];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an extension from THIS converter.
|
* Remove an extension from THIS converter.
|
||||||
* Note: This is a costly operation. It's better to initialize a new converter
|
* Note: This is a costly operation. It's better to initialize a new converter
|
||||||
|
@ -20,7 +20,21 @@ var showdown = {},
|
|||||||
ghCodeBlocks: true, // true due to historical reasons
|
ghCodeBlocks: true, // true due to historical reasons
|
||||||
tasklists: false
|
tasklists: false
|
||||||
},
|
},
|
||||||
globalOptions = JSON.parse(JSON.stringify(defaultOptions)); //clone default options out of laziness =P
|
globalOptions = JSON.parse(JSON.stringify(defaultOptions)),
|
||||||
|
flavor = {
|
||||||
|
github: {
|
||||||
|
omitExtraWLInCodeBlocks: true,
|
||||||
|
prefixHeaderId: 'user-content-',
|
||||||
|
simplifiedAutoLink: true,
|
||||||
|
literalMidWordUnderscores: true,
|
||||||
|
strikethrough: true,
|
||||||
|
tables: true,
|
||||||
|
tablesHeaderId: true,
|
||||||
|
ghCodeBlocks: true,
|
||||||
|
tasklists: true
|
||||||
|
},
|
||||||
|
vanilla: JSON.parse(JSON.stringify(defaultOptions))
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* helper namespace
|
* helper namespace
|
||||||
@ -77,6 +91,22 @@ showdown.resetOptions = function () {
|
|||||||
globalOptions = JSON.parse(JSON.stringify(defaultOptions));
|
globalOptions = JSON.parse(JSON.stringify(defaultOptions));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the flavor showdown should use as default
|
||||||
|
* @param {string} name
|
||||||
|
*/
|
||||||
|
showdown.setFlavor = function (name) {
|
||||||
|
'use strict';
|
||||||
|
if (flavor.hasOwnProperty(name)) {
|
||||||
|
var preset = flavor[name];
|
||||||
|
for (var option in preset) {
|
||||||
|
if (preset.hasOwnProperty(option)) {
|
||||||
|
globalOptions[option] = preset[option];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default options
|
* Get the default options
|
||||||
* @static
|
* @static
|
||||||
|
@ -27,6 +27,34 @@ describe('showdown.Converter', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('setFlavor() github', function () {
|
||||||
|
var converter = new showdown.Converter(),
|
||||||
|
ghOpts = {
|
||||||
|
omitExtraWLInCodeBlocks: true,
|
||||||
|
prefixHeaderId: 'user-content-',
|
||||||
|
simplifiedAutoLink: true,
|
||||||
|
literalMidWordUnderscores: true,
|
||||||
|
strikethrough: true,
|
||||||
|
tables: true,
|
||||||
|
tablesHeaderId: true,
|
||||||
|
ghCodeBlocks: true,
|
||||||
|
tasklists: true
|
||||||
|
};
|
||||||
|
|
||||||
|
converter.setFlavor('github');
|
||||||
|
|
||||||
|
for (var opt in ghOpts) {
|
||||||
|
if (ghOpts.hasOwnProperty(opt)) {
|
||||||
|
check(opt, ghOpts[opt]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function check(key, val) {
|
||||||
|
it('should set ' + opt + ' to ' + val, function () {
|
||||||
|
converter.getOption(key).should.equal(val);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
describe('extension methods', function () {
|
describe('extension methods', function () {
|
||||||
var extObjMock = {
|
var extObjMock = {
|
||||||
type: 'lang',
|
type: 'lang',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user