Blog of Sara Jakša

This Blog Now Have Syntax Highlighting

From time to time I write some snippets for code on my blog. So I was wondering if there is an easy way to do a code highlighting. I know I am not going to do it by hand. I tried that once, since I did not have a nice way to copy the code into word with syntax highlighting. I did not consider this function necessary enough to do it that way. It was disheartening.

The first solution that came to mind was to use a markdown that also has a syntax highlighting. This was eventually a dead end for me. I could not make it work.

The second one was to use some JavaScript library. Thankfully, the first result on the google ended up being the one that I ended up using.

Setting it up was fairly simply. They let people build the package of only the languages they will use, which in my case, at least for now is Python and R.

Then there are three lines of code, that I needed to put in the head of the template, and two files that I needed to transfer, one css and on javascript file.

I would like to say, that it worked. It did not. For some reason the class for my code block was generated in a way that is stopped highlighting from working. This was easily solved by adding the ```name-of-language on the beginning of the code block in my markdown file, and the ``` on the end.

I simply took one possible scheme. It works and that is important for me at this point. Maybe one day I will play with it, but not now.