blog/enrich_codeblocks.js
Louis Vallat bc2a00556a
All HTML files will be enriched once generated
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
2022-01-24 19:07:20 +01:00

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, $);
});
});