Skip to content
Snippets Groups Projects
Commit b15e4d3c authored by marihachi's avatar marihachi
Browse files

🐱

parent 771ba41f
No related branches found
No related tags found
No related merge requests found
# 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: ...@@ -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:​');
......
...@@ -47,7 +47,10 @@ export type MfmInline = MfmEmoji | MfmBold | MfmSmall | MfmItalic | MfmStrike | ...@@ -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: [];
}; };
......
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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment