~james/core

core/blog/src/dashes.mjs -rw-r--r-- 641 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// @ts-check
import { defineMdastPlugin } from "satteri";

// the go renderer's dashes (appview/pages/markup/extension/dashes.go), which the
// posts are written for: `--` is an em dash, and a hyphen between two digits
// (50-100) an en dash. satteri's own smart dashes make `--` an en dash instead, so
// they're off (astro.config.mjs) and this does the dashes; code is left alone
export const dashes = defineMdastPlugin({
	name: "tangled-dashes",
	text(node, ctx) {
		const value = node.value.replace(/--/g, "\u2014").replace(/(\d)-(?=\d)/g, "$1\u2013");
		if (value !== node.value) ctx.replaceNode(node, { type: "text", value });
	},
});