UNPKG

@rshirohara/rekurke-stringify

Version:

rekurke plugin to add support for serializing kakuyomu novel format.

56 lines (55 loc) 1.32 kB
export function toKakuyomuNovel(tree) { return [...tree.children] .map((node) => { switch (node.type) { case "paragraph": { return compileParagraph(node); } case "paragraphMargin": { return compileParagraphMargin(node); } default: { return ""; } } }) .join(""); } function compileParagraph(tree) { return [...tree.children] .map((node) => { switch (node.type) { case "break": { return compileBreak(node); } case "emphasis": { return compileEmphasis(node); } case "ruby": { return compileRuby(node); } case "text": { return compileText(node); } default: { return ""; } } }) .join(""); } function compileParagraphMargin(tree) { return "\n".repeat(tree.size + 1); } function compileBreak(_) { return "\n"; } function compileEmphasis(tree) { return `《《${tree.value}》》`; } function compileRuby(tree) { return `|${tree.value}${tree.ruby}》`; } function compileText(tree) { return tree.value; }