blob: 362994ab605ceeaf190131ba9bbed55579f6b92e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#!/usr/bin/node
// Server side syntax highlight with Shiki https://shiki.matsu.io/
// This script is replacement for pygments/highlight for cgit
// Shiki is installed with `npm install -g shiki`
// input: filename, stdin - source file. Outputs the highligted html to stdout.
import { argv, stdin, stdout } from 'node:process';
import { codeToHtml } from "/usr/lib/node_modules/shiki/dist/index.mjs";
async function highlight(syntax) {
stdin.on("data", async (data) => {
const text = Buffer.from(data).toString("utf8");
const html = await codeToHtml(text, {
lang: syntax,
theme: "gruvbox-dark-soft"
});
stdout.write(html);
});
return true
}
const filename = argv[1];
const lang = filename.split(".")[1];
highlight(lang);
|