A pastebin for markdown pages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.3 KiB

// jscs:disable maximumLineLength
/**
* Highlight Module
*
*
* High Level API:
*
* api.init()
*
*
* Hooks To:
*
* 'document:loaded' ~> highlight.init();
*
*/
(function (global) {
function loadInitialScriptsAndStyles() {
var link =
document.createElement('link');
var mainScript =
document.createElement('script');
link.rel =
'stylesheet';
link.href =
'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/railscasts.min.css';
mainScript.src =
'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js';
// On main script load, configure marked
mainScript.addEventListener('load', function () {
marked.setOptions({
langPrefix: 'hljs lang-',
highlight: function (code) {
return hljs.highlightAuto(code).value;
},
});
});
// Extend marked.js on edit page only
if ('marked' in global) {
document.body.appendChild(mainScript);
}
// Preview page requires scripts only
document.head.appendChild(link);
}
// High Level API
var api = {
init: function () {
loadInitialScriptsAndStyles();
},
};
// Hooks
if ('events' in global) {
events.subscribe('document:loaded', api.init);
}
}(window));