0.1.2 • Published 9 months ago

@rshirohara/rekurke-parse v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

rekurke-parse

LICENSE

rekurke plugin to support for parsing kakuyomu novel format.

Contents

What is this?

This package is a unified plugin that defines how to take kakuyomu novel format as input and turn it into a syntax tree.

Install

This package is ESM only. in Node.js (18.0+), Install with npm:

npm install @rshirohara/rekurke-parse

Use

Say we have the following module example.js:

import { rekurkeParse } from "@rshirohara/rekurke-parse";
import { unified } from "unified";

main();

async function main() {
  const source = [
    "これが一段落目\r\n",
    "ここから二段落目",
    "これはルビ|振《ふ》り",
    "これは《《強調》》",
  ].join("\n");
  const ast = await unified().use(rekurkeParse).parse(source);

  console.log(ast);
}

Running that with node example.js yields:

{
  type: "root",
  children: [
    {
      type: "paragraph",
      children: [{ type: "text", value: "これが一段落目" }],
    },
    {
      type: "paragraphMargin",
      size: 1,
    },
    {
      type: "paragraph",
      children: [
        { type: "text", value: "ここから二段落目" },
        { type: "break" },
        { type: "text", value: "これはルビ" },
        { type: "ruby", value: "振", ruby: "ふ" },
        { type: "text", value: "り" },
        { type: "break" },
        { type: "text", value: "これは" },
        { type: "emphasis", value: "強調" },
      ],
    },
  ],
}

API

unified().use(rekurkeParse)

Add support for parsing kakuyomu novel format input. There are no options.

Syntax

Kakuyomu novel format text is parsed according to the official documentation.

Syntax Tree

The syntax tree format uses in rekurke is kkast.

Types

This package is fully typed with TypeScript. There are no extra exported types.

License

MIT

0.1.2

9 months ago

0.1.1

10 months ago

0.1.0

1 year ago