23 lines
705 B
JavaScript
23 lines
705 B
JavaScript
|
const Prism = require('prismjs');
|
||
|
const fs = require('fs');
|
||
|
const cheerio = require('cheerio');
|
||
|
const loadLanguages = require('prismjs/components/');
|
||
|
const fsc = require('fs-cheerio');
|
||
|
|
||
|
loadLanguages([
|
||
|
'rust', 'py', 'cpp', 'c', 'git'
|
||
|
]);
|
||
|
|
||
|
fs.readdirSync("./dst/").filter(e => e.endsWith(".html")).forEach(file => {
|
||
|
console.log("Enriching " + file)
|
||
|
fsc.readFile("./dst/" + file).then(function ($) {
|
||
|
$('*[class^="language-"]').replaceWith(function () {
|
||
|
return $(this).html(Prism.highlight(
|
||
|
$(this).text(),
|
||
|
Prism.languages[$(this).attr('class').split('-')[1]])
|
||
|
);
|
||
|
});
|
||
|
fsc.writeFile("./dst/" + file, $);
|
||
|
});
|
||
|
});
|