This commit is contained in:
parent
4b3aa3022e
commit
632543db4d
55 changed files with 432 additions and 117 deletions
22
sites/puzzles/src/remark/typography.mjs
Normal file
22
sites/puzzles/src/remark/typography.mjs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
const EM_DASH_PATTERN = /---/g;
|
||||
|
||||
function visitTextNodes(node) {
|
||||
if (!node || typeof node !== "object") return;
|
||||
|
||||
if (node.type === "text" && typeof node.value === "string") {
|
||||
node.value = node.value.replace(EM_DASH_PATTERN, "—");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Array.isArray(node.children)) return;
|
||||
|
||||
for (const child of node.children) {
|
||||
visitTextNodes(child);
|
||||
}
|
||||
}
|
||||
|
||||
export default function remarkTypography() {
|
||||
return (tree) => {
|
||||
visitTextNodes(tree);
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue