diff --git a/README.md b/README.md index a038e83f268b6e93f450910acb01db3558499248..5ac444a1fccab52169ac0dc5affbde1de17bfa40 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # rosee ## Description -A MFM parser implementation with PEG.js (In developing) +A MFM parser implementation with PEG.js ## Installation ``` @@ -12,8 +12,17 @@ TypeScript: ```ts 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 -const result = mfm.parse('good morning ***everynyan!***'); +const result = mfm.parse(input); // parse a MFM plain text const plainResult = mfm.parsePlain('I like the hot soup :soup:​'); diff --git a/src/node.ts b/src/node.ts index 3827b38a702f39b74df59458c76c64201877f0ef..1d6456a8c68bc4f65971135680499d179c593bd8 100644 --- a/src/node.ts +++ b/src/node.ts @@ -47,7 +47,10 @@ export type MfmInline = MfmEmoji | MfmBold | MfmSmall | MfmItalic | MfmStrike | export type MfmEmoji = { type: 'emoji'; - props: { emoji: string; name: undefined; } | { emoji: undefined; name: string; }; + props: { + emoji?: string; + name?: string; + }; children: []; }; diff --git a/src/util.ts b/src/util.ts index 83b2dc6f72936a9660020a8ae77f8aa04afa3e0c..4f4387361cc9ee6af2ec597d1541f33e92db2250 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,6 +1,6 @@ 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 ?? {}; children = children ?? []; const node = { type, props, children } as MfmNode;