Forked from https://github.com/emallson/hexo-theme-tufte
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.
18 lines
636 B
18 lines
636 B
var hljs = require('highlight.js'),
|
|
jsdom = require('jsdom');
|
|
|
|
hexo.extend.filter.register('after_post_render', function(data) {
|
|
var document = jsdom.jsdom(data.content);
|
|
var codes = document.querySelectorAll('pre code');
|
|
|
|
Array.prototype.forEach.call(codes, function(code) {
|
|
if(code.className === 'plain') {
|
|
return;
|
|
} else if(code.className) {
|
|
code.innerHTML = hljs.highlight(code.className, code.innerHTML).value;
|
|
} else {
|
|
code.innerHTML = hljs.highlightAuto(code.innerHTML).value;
|
|
}
|
|
});
|
|
data.content = jsdom.serializeDocument(document);
|
|
});
|