This commit is contained in:
marihachi 2021-03-21 00:36:54 +09:00
parent 771ba41ff8
commit b15e4d3c2e
3 changed files with 16 additions and 4 deletions

View file

@ -1,6 +1,6 @@
# rosee # rosee
## Description ## Description
A MFM parser implementation with PEG.js (In developing) A MFM parser implementation with PEG.js
## Installation ## Installation
``` ```
@ -12,8 +12,17 @@ TypeScript:
```ts ```ts
import * as mfm from 'rosee'; import * as mfm from 'rosee';
const input =
`<center>
Hello [tada everynyan! 🎉]
I'm @ai, An bot of misskey!
https://github.com/syuilo/ai
</center>`;
// parse a MFM text // parse a MFM text
const result = mfm.parse('good morning ***everynyan!***'); const result = mfm.parse(input);
// parse a MFM plain text // parse a MFM plain text
const plainResult = mfm.parsePlain('I like the hot soup :soup:'); const plainResult = mfm.parsePlain('I like the hot soup :soup:');

View file

@ -47,7 +47,10 @@ export type MfmInline = MfmEmoji | MfmBold | MfmSmall | MfmItalic | MfmStrike |
export type MfmEmoji = { export type MfmEmoji = {
type: 'emoji'; type: 'emoji';
props: { emoji: string; name: undefined; } | { emoji: undefined; name: string; }; props: {
emoji?: string;
name?: string;
};
children: []; children: [];
}; };

View file

@ -1,6 +1,6 @@
import { MfmNode, MfmText } from './node'; import { MfmNode, MfmText } from './node';
export function createNode(type: string, props?: Record<string, any>, children?: MfmNode[]): MfmNode { export function createNode(type: string, props: Record<string, any>, children?: MfmNode[]): MfmNode {
props = props ?? {}; props = props ?? {};
children = children ?? []; children = children ?? [];
const node = { type, props, children } as MfmNode; const node = { type, props, children } as MfmNode;