#!/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);