@rshirohara/repixe-stringify
Version:
repixe plugin to add support for serializing pixiv novel format.
149 lines (114 loc) • 3.46 kB
Markdown
[![LICENSE][license-badge]][license]
**repixe** plugin to add support for serializing [pixiv novel][pixiv-novel] format.
- [repixe-stringify](
- [Contents](
- [What is this?](
- [Install](
- [Use](
- [API](
- [`unified().use(repixeStringify)`](
- [Syntax](
- [Syntax tree](
- [Types](
- [License](
This package is a [unified][] plugin that defines how to take a syntax tree
as input and turn it into serialized [pixiv novel][pixiv-novel] format.
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
in Node.js (18.0+), Install with [npm][]:
```shell
npm install @rshirohara/repixe-stringify
```
Say we have the following module `example.js`
```js
import { unified } from "unified";
import { repixeStringify } from "@rshirohara/repixe-stringify";
main();
async function main() {
const source = {
type: "root",
children: [
{
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: "pageBreak" },
{
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:
```text
ここが一段落目。
ここが二[[rb: 段落 > だんらく]]目。
ここが二行目。
ここから三段落目。
[[jumpuri: リンク > https://example.com]]も使える。
[]
ここからページが変わる。
[]ページへの参照。
```
Add support for serializing pixiv novel format input.
There are no options.
This package serializes according to [pixiv novel][pixiv-novel] format.
The syntax tree format used in repixe is [pxast][].
This package is fully typed with [TypeScript][].
There are no extra exported types.
[][license]
<!-- Link Definitions -->
[]: https://img.shields.io/github/license/RShirohara/unified-webnovel
[]: ./LICENSE.md
[]: https://docs.npmjs.com/cli/install
[]: https://www.pixiv.net/novel
[]: ../pxast
[]: https://www.typescriptlang.org
[]: https://github.com/unifiedjs/unified