Midnight Pub

Small proof of concept: text replacement in editor boxes


As much as I appreciate the minimalism of our posts here, sometimes I want just a tiny bit more. Just little replacements, like curly quotes (“”) or whatever.

Thankfully, the midnight is set up such that you can add custom JavaScript to your site theme. It only works for you (while logged in), so there’s no worry about screwing up the experience for anyone else. At least not without *really* trying.

So it is that I put together a little script:


If you’re interested in adding this to your own theme, just follow these steps:

1. From the midnight home page, click [Account], and then [Theme]

2. At the very bottom of the text box, enter the following:


This tells the web browser that anything after that is not styling for the page.

From here, you have two options:

1. Use my script as-is, subject to whatever changes I may decide to make. If you want to go this route, add the following on the line after </style>:

<script src="https://zampano.midnight.pub/textreplace.js"></script>

2. In the alternative, you can copy my script so that you can make any changes you want (and so any changes I make won’t affect you). To do this, first add the following on the line below </style>:


Next, click on the link above (the one ending in “textreplace.js”), and it’ll take you to the script itself. Copy the whole thing, and paste it on your theme below the text you just added (<script>). Finally, on the first blank line under what you’ve pasted, add this:


Then just save the page and you’re done!

A couple notes. First, it should apply equally to any text editor on the site, whether that’s for adding a new post or replying to someone else’s. But this also means that it applies to the built-in editor for things like your site theme, which will not work with e.g. curly quotes.

If there’s demand, I can add a way to disable it (either manually with a button or based on the page address). For me, though, it’s easier to just write any code in a separate editor, since those are better for that purpose anyway.

I hope someone else finds this useful! If you need help with either getting it up and running or with adding some new replacements, feel free to let me know. I’m always on the lookout for new coding projects too, so if you have any “it’d be nice if” things, definitely let me know those as well!