@rshirohara/repixe-rekurke
Version:
repixe plugin that turns pixiv novel format into kakuyomu novel format to support rekurke.
34 lines (33 loc) • 920 B
JavaScript
export const postprocess = (node, options) => {
const processors = [
removeEmptyNode,
insertParagraphMargin,
];
let result = { ...node };
for (const processor of processors) {
result = processor(result, options);
}
return result;
};
function removeEmptyNode(node, _) {
function removeNode(node) {
if (node.type === "paragraph" && node.children.length === 0) {
return undefined;
}
return node;
}
return {
...node,
children: [...node.children]
.map((node) => removeNode(node))
.filter((node) => node !== undefined),
};
}
function insertParagraphMargin(node, _) {
return {
...node,
children: [...node.children].flatMap((value, index) => index + 1 < node.children.length
? [value, { type: "paragraphMargin", size: 1 }]
: [value]),
};
}