/html-syntax-highlight

highlights code within an html file

Primary LanguageGoMIT LicenseMIT

Highlight code on a static html file

This program parses an html file and adds chroma classes to code within pre and code tags. Then you can add chroma themes with css.

Running

Make sure you have golang installed (if not, follow this instructions) then run:

$ go run main.go <test_file.html>

with <test_file.html> being an html file containing some code to highlight.

Input file format

This is an example of a code snippet contained within an html file that this program adds chroma css classes

(...)
<pre><code class="language-c">
#include <stdio.h>

int main(void) {
    char *hw = "Hello, world!\n";

    printf("%s\n", hw);
    return 0;
}
</code></pre>
(...)

To capture the code snippet it uses regular expression so it should be easier to adapt to other formats.

Example

The main purpose of this program was to highlight code snippets on my blog. Checkout this post that I made to test it.

License

MIT