blog/enrich_codeblocks.js

21 lines
565 B
JavaScript
Raw Normal View History

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'
]);
const file = process.argv[2];
fsc.readFile(file).then(function ($, err) {
$('*[class^="language-"]').replaceWith(function () {
return $(this).html(Prism.highlight(
$(this).text(),
Prism.languages[$(this).attr('class').split('-')[1]])
);
});
fsc.writeFile(file, $);
});