0.2.3 • Published 1 month ago
@rshirohara/repixe-stringify v0.2.3
repixe-stringify
repixe plugin to add support for serializing pixiv novel format.
Contents
What is this?
This package is a unified plugin that defines how to take a syntax tree as input and turn it into serialized pixiv novel format.
Install
This package is ESM only. in Node.js (18.0+), Install with npm:
npm install @rshirohara/repixe-stringify
Use
Say we have the following module example.js
import { unified } from "unified";
import { repixeStringify } from "@rshirohara/repixe-stringify";
main();
async function main() {
const source = {
type: "root",
children: [
{ type: "pageHeading", pageNumber: 1 },
{
type: "paragraph",
children: [
{
type: "text",
value: "ここが一段落目。"
}
]
},
{
type: "paragraph",
children: [
{ type: "text", value: "ここが二" },
{ type: "ruby", value: "段落", ruby: "だんらく" },
{ type: "text", value: "目。" },
{ type: "break" },
{ type: "text", value: "ここが二行目。" }
]
},
{
type: "paragraph",
children: [
{ type: "text", value: "ここから三段落目。" },
{ type: "break" },
{
type: "link",
url: "https://example.com",
children: [{ type: "text", value: "リンク" }]
},
{ type: "text", value: "も使える。" }
]
},
{ type: "pageHeading", pageNumber: 2 },
{
type: "paragraph",
children: [
{ type: "text", value: "ここからページが変わる。" },
{ type: "break" },
{ type: "pageReference", pageNumber: 1 },
{ type: "text", value: "ページへの参照。" }
]
}
]
};
const result = await unified().use(repixeStringify).compile(source);
console.log(result);
}
Running that with node example.js
yields:
ここが一段落目。
ここが二[[rb: 段落 > だんらく]]目。
ここが二行目。
ここから三段落目。
[[jumpuri: リンク > https://example.com]]も使える。
[newpage]
ここからページが変わる。
[jump:1]ページへの参照。
API
unified().use(repixeStringify)
Add support for serializing pixiv novel format input. There are no options.
Syntax
This package serializes according to pixiv novel format.
Syntax tree
The syntax tree format used in repixe is pxast.
Types
This package is fully typed with TypeScript. There are no extra exported types.