html-syntax-highlighthighlight code within an html file |
Mode | Name | Size |
-rw-r--r-- | LICENSE | 21L |
-rw-r--r-- | README.md | 43L |
-rw-r--r-- | go.mod | 14L |
-rw-r--r-- | go.sum | 26L |
-rw-r--r-- | main.go | 117L |
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.
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.
This is an example of a code snippet within an html file that this program
should add 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>
(...)
But it uses regular expression so it should be easier to adapt to other formats.
The main purpose of this program was to highlight code snippets on my blog. Checkout this post that I made to test it.