{
  "$type": "site.standard.document",
  "content": "---\ntitle: \"highlight.js with xtlang support\"\ndescription: \"Getting syntax highlighting for Extempore's xtlang working on this blog, told\n  as an FAQ full of hacks and node build shenanigans.\"\ntags:\n  - dev\n---\n\n:::tip\n\n**Note**: adding syntax-highlighted xtlang to your website is now easier than\never because\n[highlightjs-extempore](https://github.com/highlightjs/highlightjs-extempore) is\nan official hljs module. While this page is still an interesting dive into how I\ndid it at the time, you should now just follow the instructions on GitHub.\n\n:::info\n\n> It is a truth, universally acknowledged, that all programming language authors\n> must also be expert web developers. (_attributed to Jane Austen_)\n\nI've just spent a solid day wrestling with source code syntax highlighting on my\nblog, and I've finally got it figured out. Tada:\n\n```armasm\nlabelious:\n  sub r0, 1\n  bne doneski\n  b labelious\n\ndoneski:\n  nop\n```\n\nI know you've got questions, so the rest of this post will be structured as an\n**FAQ**.\n\n## FAQ\n\n### Why did you even do that? It seemed to be working fine before.\n\nYes, well, it was mostly working fine. But I was just using an\noff-the-shelf[^cdn] disribution of [highlight.js](https://highlightjs.org/),\nwhich supported a bunch of languages but not all the ones I need. Especially\nExtempore, which is super-important for showing off my livecoding stuff on this\nblog.\n\n[^cdn]: well, off-the-CDN, anyway\n\n### Does Extempore/xtlang have highlight.js support now?\n\nYep, [`@blue9`](https://github.com/cyblue9) ported the\n[Scheme/xtlang lexer](https://bitbucket.org/birkenfeld/pygments-main/src/7941677dc77d4f2bf0bbd6140ade85a9454b8b80/pygments/lexers/lisp.py?at=default&fileviewer=file-view-default#lisp.py-2420)\nthat I wrote for Pygments, which is a _big_ help to the Extempore community\n(thanks `blue9`).\n\n### Isn't it just a matter of adding `xtlang` to the highlight.js build step?\n\nNo, because [reasons](https://github.com/highlightjs/highlightjs-xtlang#usage).\nIt's a real mess, and we're waiting on\n[this PR](https://github.com/highlightjs/highlight.js/pull/1888) to land before\nit gets easier.\n\n### How'd you get it working, then?\n\nHacks upon hacks. If you really wanna know, it's in\n[this branch](https://github.com/benswift/benswift.github.io/tree/hljs-with-xtlang)\n(although the final product, `highlight.pack.js` is in the main `source`\nbranch).\n\nBasically, I backported the Extempore language support from the new \"plugin\" way\nof doing things (which is better, but doesn't really work yet) to the old\n\"built-in\" way of doing things, and then generated a new, custom build of\nhighlight.js which included both xtlang and all the other languages that I need\nfor my blog.\n\n### So can I see some xtlang code, then?\n\nSure, here's an example function from\n[`examples/core/extempore_lang.xtm`](https://github.com/digego/extempore/blob/master/examples/core/extempore_lang.xtm).\n\n```xtlang\n(bind-func my-test-7\n  (lambda ()\n    (let ((a:<i64,double>* (alloc)) ; returns pointer to type <i64,double>\n          (b 37)\n          (c 6.4))\n      (tuple-set! a 0 b) ;; set i64 to 64\n      (tset! a 1 c) ;; set double to 6.4 - tset! is an alias for tuple-set!\n      (printf \"tuple:1 %lld::%f\\n\" (tuple-ref a 0) (tref a 1))\n      ;; we can fill a tuple in a single call by using tfill!\n      (tfill! a 77 77.7)\n      (printf \"tuple:2 %lld::%f\\n\" (tuple-ref a 0) (tuple-ref a 1))\n      (tuple-ref a 0)))) ;; return first element which is i64\n```\n\n### When will we get this syntax colouring goodness when viewing Extempore code on GitHub?\n\nGitHub doesn't use highlight.js, it uses\n[linguist](https://github.com/github/linguist) for this sort of thing. So\ngetting it working on GH would involve porting the language definitions to that\nproject as well.\n\n### Will it always be this complicated to set up?\n\nNo, once the\n[aformentioned issue](https://github.com/highlightjs/highlight.js/pull/1888) is\nsorted out, it should be much easier to get a \"base\" package of highlight.js\nfrom the main download website/CDN, and then to add any extras (e.g.\nExtempore/xtlang) as needed. But until that happens, shenanigans are required.\n\n### What's with the Jane Austen quote above, then?\n\nFiguring this all out required a lot of digging around in existing packages,\nlearning a new [node-based build system](https://www.npmjs.com/package/gear) and\na bunch of other things. I'm pretty capable with this sort of thing, so I got\nthere in the end. But it does make me a bit sad that the job of building a\ncommunity around a programming language involves so much stuff that doesn't use\nthe language itself, and these days invariably involves poking around various\nnpm packages and staring at the Chrome developer tools.\n\n### Can I use your build of highlight.js to font-lock xtlang code on my own site?\n\nSure, I'd be pumped if you did. If you want, you can check out the\n[`hljs-with-xtlang` branch](https://github.com/benswift/benswift.github.io/tree/hljs-with-xtlang)\nof this repo and follow the instructions therein to make your own custom build.\nOr, if you don't want to do that, you could just use the one you've already\ndownloaded (since you're visiting this website).\n",
  "createdAt": "2026-05-13T23:15:01.461Z",
  "description": "Getting syntax highlighting for Extempore's xtlang working on this blog, told as an FAQ full of hacks and node build shenanigans.",
  "path": "/blog/2019/01/17/highlight-js-with-xtlang-support",
  "publishedAt": "2019-01-17T00:00:00.000Z",
  "site": "at://did:plc:tevykrhi4kibtsipzci76d76/site.standard.publication/self",
  "tags": [
    "dev"
  ],
  "textContent": "Getting syntax highlighting for Extempore's xtlang working on this blog, told as an FAQ full of hacks and node build shenanigans.",
  "title": "highlight.js with xtlang support"
}