Non-breaking Em Dashes

This little snippet of code from Robin Sloan is very nice. It’s basically a regular expression that rewrites your HTML so that a line will never begin with an em dash. It also bookends the em dash with very thin spaces, which look just a bit nicer.

Now I have to work out how to apply it to the posts on this site, which are generated by Hugo. It’d be relatively easy if I were just running Hugo locally and deploying from my local machine, but I’m using Netlify to build and deploy. It seems like it might be possible to do if I write a plugin that runs after a build. All I have to do is work out what Javascript is needed to run the regular expression, get it to do that to a bunch of files at once, and then discover what magical incantations are needed to make the whole thing work.

Sounds like a nice holiday project.