Syntax highlighting is essential for blogging program code. Many blog hosts recognize this and provide tools for highlighting programming languages. WordPress.com (this host) has a nifty highlighting tool that handles dozens of mainstream programming languages. Unfortunately, one of my favorite programming languages, J, (yes it’s a single letter name), is way out of the mainstream and is not supported.
There are a few ways to deal with this problem.
- Eschew J highlighting.
- Upgrade1 your WordPress.com subscription and install custom syntax highlighters that can handle arbitrary language definitions.
- Find another blog host that freely supports custom highlighters.
- Roll your own or customize an existing highlighter.
A few years ago I went with the fourth option and hacked the superb open-source tool pandoc. The grim details are described in this blog post. My hack produced a customized version of pandoc with J highlighting. I still use my hacked version and I’d probably stick with it if current pandoc versions had not introduced must-have features like converting Jupyter notebooks to Markdown, PDF, LaTeX and HTML. Jupyter is my default thinking-things-through programming environment. I’ve even taken to blogging with Jupyter notebooks. If you write and explain code you owe it to yourself to give Jupyter a try.
Unwilling to eschew J highlighting or forgo Jupyter I was on the verge of re-hacking pandoc when I read the current pandoc (version 126.96.36.199) documentation and saw that J is now officially supported by pandoc. You can verify this with the shell commands.
The pandoc developers made my day! I felt like Wayne meeting a rock star.
Highlighting J is now a simple matter of placing J code in markdown blocks like:
and issuing shell commands like:
The previous command generated the HTML of this post which I pasted into the WordPress.com Classic Editor. Not only do I get J code highlighting on the cheap I also get footnotes which, for god freaking sakes,2 are not supported by the new WordPress block editor for low budget blogs.
The source markdown used for this post is available here – enjoy!
- The pay more option is always available.
- WordPress.com is beginning to remind me of Adobe. Stop taking away longstanding features when upgrading!