Stackedit/res/extensions/markdownExtra.js

72 lines
3.1 KiB
JavaScript
Raw Normal View History

2013-05-27 19:45:33 +00:00
define([
2013-07-09 22:57:24 +00:00
"jquery",
2013-07-28 17:14:42 +00:00
"underscore",
2013-05-27 19:45:33 +00:00
"utils",
2013-06-22 23:48:57 +00:00
"classes/Extension",
"text!html/markdownExtraSettingsBlock.html",
2013-06-10 21:22:32 +00:00
"libs/Markdown.Extra",
2013-07-28 17:14:42 +00:00
], function($, _, utils, Extension, markdownExtraSettingsBlockHTML) {
2013-05-29 19:55:23 +00:00
2013-06-22 23:48:57 +00:00
var markdownExtra = new Extension("markdownExtra", "Markdown Extra", true);
markdownExtra.settingsBlock = markdownExtraSettingsBlockHTML;
markdownExtra.defaultConfig = {
2013-07-09 22:57:24 +00:00
extensions: [
"fenced_code_gfm",
"tables",
"def_list",
"attr_list",
"footnotes"
],
highlighter: "prettify"
2013-05-25 18:13:59 +00:00
};
2013-05-29 19:55:23 +00:00
2013-05-25 18:13:59 +00:00
markdownExtra.onLoadSettings = function() {
2013-07-09 22:57:24 +00:00
function hasExtension(extensionName) {
return _.some(markdownExtra.config.extensions, function(extension) {
return extension == extensionName;
});
}
utils.setInputChecked("#input-markdownextra-fencedcodegfm", hasExtension("fenced_code_gfm"));
utils.setInputChecked("#input-markdownextra-tables", hasExtension("tables"));
utils.setInputChecked("#input-markdownextra-deflist", hasExtension("def_list"));
utils.setInputChecked("#input-markdownextra-attrlist", hasExtension("attr_list"));
utils.setInputChecked("#input-markdownextra-footnotes", hasExtension("footnotes"));
utils.setInputValue("#input-markdownextra-highlighter", markdownExtra.config.highlighter);
2013-05-25 18:13:59 +00:00
};
2013-05-29 19:55:23 +00:00
2013-05-25 18:13:59 +00:00
markdownExtra.onSaveSettings = function(newConfig, event) {
2013-07-09 22:57:24 +00:00
newConfig.extensions = [];
utils.getInputChecked("#input-markdownextra-fencedcodegfm") && newConfig.extensions.push("fenced_code_gfm");
utils.getInputChecked("#input-markdownextra-tables") && newConfig.extensions.push("tables");
utils.getInputChecked("#input-markdownextra-deflist") && newConfig.extensions.push("def_list");
utils.getInputChecked("#input-markdownextra-attrlist") && newConfig.extensions.push("attr_list");
utils.getInputChecked("#input-markdownextra-footnotes") && newConfig.extensions.push("footnotes");
newConfig.highlighter = utils.getInputValue("#input-markdownextra-highlighter");
2013-05-25 00:34:04 +00:00
};
2013-05-29 19:55:23 +00:00
2013-09-09 23:32:24 +00:00
markdownExtra.onPagedownConfigure = function(editor) {
2013-05-29 19:55:23 +00:00
var converter = editor.getConverter();
2013-07-09 22:57:24 +00:00
var options = {
extensions: markdownExtra.config.extensions
};
if(markdownExtra.config.highlighter == "highlight") {
options.highlighter = "prettify";
2013-07-28 17:14:42 +00:00
var previewContentsElt = document.getElementById('preview-contents');
2013-07-09 22:57:24 +00:00
editor.hooks.chain("onPreviewRefresh", function() {
2013-07-28 17:14:42 +00:00
_.each(previewContentsElt.querySelectorAll('.prettyprint'), function(elt) {
hljs.highlightBlock(elt);
2013-07-09 22:57:24 +00:00
});
});
}
else if(markdownExtra.config.highlighter == "prettify") {
2013-05-29 19:55:23 +00:00
options.highlighter = "prettify";
editor.hooks.chain("onPreviewRefresh", prettyPrint);
}
Markdown.Extra.init(converter, options);
2013-07-28 17:14:42 +00:00
2013-07-23 23:51:21 +00:00
// Store extensions list in converter for partialRendering
converter.extraExtensions = markdownExtra.config.extensions;
2013-05-29 19:55:23 +00:00
};
2013-05-25 00:34:04 +00:00
return markdownExtra;
});