Hack Tree-Sitters HTML Debug Output To Dark Mode

I'm working on a Tree-Sitter^ts^^ parser for Neopolitan. I'm using the `-D`` flag for command line tests to produce a `log.html`` file with a visual graph of the output. It's easier to figure out what's going on when things aren't going right.

The graph is produced by graphviz^gv^^ via an internal call STDIN call. The output is black text on a white background. As someone who like working in dark mode it's a bit of a flash-bang every time I switch to it.

To fix that, I pulled down the source code^sc^^ and made the following edits:

Add this to the style sheet section

Code
body {
    background-color: darkslategray;
}


Change:
Code
fprintf(self->dot_graph_file, "graph {\nlabel=\"");

To:

Code
fprintf(self->dot_graph_file, "graph {\nbgcolor=\"darkslategray\"\nlabel=\"");

Change:

Code
fprintf(f, "digraph stack { \n");

To:

Code
fprintf(f, "digraph stack { \nbgcolor=\"darkslategray\"\n");

Change:

Code
fprintf(f, "digraph tree {\n");

To:

Code
fprintf(f, "digraph tree {\nbgcolor=\"darkslategray\"\n");

Installing The Hack

Installing the modified version of Tree-Sitter is done by running:

Code
cargo install --path cli

That drops the binary under:

~/.cargo/bin/tree-sitter

My main tree-sitter is under:

Code
/opt/homebrew/bin/tree-sitter

I could switch things around to use the new one 100% of the time, but I just call the `~/.cargo/bin`` version directly when testing like:

Code
~/.cargo/bin/tree-sitter test
Notes
  • The above changes the background color only. The text and lines stay black. It's possible to change them as well, but this is fine for me

  • graphviz must be installed to generate the html. I got it using the homebrew command `brew install graphviz``

Reference

Graphviz - open source graph visualization software

Reference

Tree-Sitter Source Code

Reference

Tree-Sitter - a parser generator tool and an incremental parsing library

If all goes well, this is what I'll be using to do syntax highlighting for neopolitan in neovim