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.

58 lines
955 B

var path = require('path');
var hljs = require('highlight.js');
var MAP = {
'py': 'python',
'js': 'javascript',
'json': 'javascript',
'rb': 'ruby',
'csharp': 'cs',
};
function normalize(lang) {
if(!lang) { return null; }
var lower = lang.toLowerCase();
return MAP[lower] || lower;
}
function highlight(lang, code) {
if(!lang) return {
body: code,
html: false
};
// Normalize lang
lang = normalize(lang);
try {
return hljs.highlight(lang, code).value;
} catch(e) { }
return {
body: code,
html: false
};
}
module.exports = {
book: {
assets: './css',
css: [
'website.css'
]
},
ebook: {
assets: './css',
css: [
'ebook.css'
]
},
blocks: {
code: function(block) {
return highlight(block.kwargs.language, block.body);
}
}
};