This commit is contained in:
marihachi 2020-02-24 22:27:01 +09:00
parent ed85121c5a
commit 753cb6deff
3 changed files with 14 additions and 7 deletions

View file

@ -9,10 +9,13 @@ npm i mfm-parser-pegjs
## Usage
```ts
import { parse } from 'mfm-parser-pegjs';
import * as mfm from 'mfm-parser-pegjs';
// parse a MFM code
const result = parse('this is a ***MFM text***');
// parse a MFM text
const result = mfm.parse('good morning ***everyone!***');
// parse a MFM plain text
const plainResult = mfm.parsePlain('I like the hot soup :soup:');
```
## Usage (Repository)
@ -39,6 +42,3 @@ npm run parse
## License
This software is released under the [MIT License](LICENSE).
This software includes codes of other softwares:
- PEG.js: https://raw.githubusercontent.com/pegjs/pegjs/master/LICENSE

View file

@ -1,6 +1,6 @@
{
"name": "mfm-parser-pegjs",
"version": "0.1.1",
"version": "0.1.3",
"description": "A MFM parser made with PEG.js",
"main": "./built/index.js",
"scripts": {
@ -18,6 +18,7 @@
"url": "git+https://github.com/marihachi/mfm-parser-pegjs.git"
},
"author": "Marihachi",
"license": "MIT",
"devDependencies": {
"@types/node": "^12.0.4",
"@types/parsimmon": "^1.10.1",

View file

@ -12,3 +12,9 @@ export function parse(input: string) {
trees = coreParser.parse(input);
return trees;
}
export function parsePlain(input: string) {
let trees: Tree[];
trees = coreParser.parse(input, { startRule: 'plainParser' });
return trees;
}