hylite is a CLI tool for turning source code into HTML using highlight.js.
It's best explained with a quick demo:
> hylite --version
1.0.7
> echo '{"foo": true}' | hylite -l json
<span class="hljs-punctuation">{</span><span class="hljs-attr">"foo"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">}</span>
I.e. you feed the CLI some source and a language. If you give it a file, it figures out the language by the file extension. For example:
> hylite test.yml
<span class="hljs-attr">foo:</span>
<span class="hljs-bullet">-</span> <span class="hljs-string">bar</span>
Anyway, the project has been around for some time. It's written in Bun and as of version 1.0.7, from now every release is uploaded to GitHub as release asset files. You can see them on: https://github.com/peterbe/hylite
Each file is an executable for different hardware and operating systems.
Here's an example of how I use it for this very blog's admin tool that converts code snippets in within Markdown. (The Markdown-to-HTML is written in Python, but code snippets are subprocess piped to hylite
because none of the Python Markdown syntax highlighters were good enough. Especially with JSX)
#!/bin/bash
set -e
wget -O /tmp/hylite-linux-x64 https://github.com/peterbe/hylite/releases/latest/download/hylite-linux-x64
chmod +x /tmp/hylite-linux-x64
echo "Version of recent download:"
/tmp/hylite-linux-x64 --version
mv /tmp/hylite-linux-x64 ~/bin
cd ~/bin
rm -f hylite
ln -s hylite-linux-x64 hylite
echo "Version of installed hylite:"
hylite --version
Essentially, it downloads the latest hylite-linux-x64
for this server and moves it into that $PATH
under the name hylite
. Now, you get a super fast code-to-HTML converter as a single executable. No need for npx
or node_modules
or even bun
.
Bonus speed test
By the way, it's fast.
The command:
hylite test.yml
takes on average 32 milliseconds to fully run.
And because the project is written in regular TypeScript, it builds a dist/index.js
file. So you can equally run node dist/index.js test.yml
or bun run dist/index.js test.yml
. Those take 62 milliseconds and 44 milliseconds respectively.
Comments