mirror of
https://github.com/kogakure/website-astro-stefanimhoff.de.git
synced 2026-02-03 20:15:27 +00:00
18 lines
389 B
TypeScript
18 lines
389 B
TypeScript
import { visit } from 'unist-util-visit';
|
|
|
|
import type { Literal, Node } from 'unist';
|
|
|
|
export function remarkWidont() {
|
|
function transformer(tree: Node) {
|
|
visit(tree, 'text', function (node: Literal<string>) {
|
|
let wordCount = node.value.split(' ').length;
|
|
|
|
if (wordCount >= 3) {
|
|
node.value = node.value.replace(/ ([^ ]*)$/, '\u00A0$1');
|
|
}
|
|
});
|
|
}
|
|
|
|
return transformer;
|
|
}
|