2021-03-26 14:20:12 +00:00
|
|
|
|
# mfm.js
|
TypeScript版パーサーのマージ (#124)
* implement parser with TypeScript (#116)
* clean parser
* parser, success, failure, str, parser.map
* seq
* atLeast, any, alt, match, notMatch
* mergeText
* improve seq
* lazy, createLanguage
* types
* regexp, refactor
* nest limit
* lint
* state
* syntaxes
* sep1, succeeded, option, fn
* simple
* strikeWave, plainTag, inlineCode, mathInline
* mention, refactor
* seqPartial
* :rocket:
* parser trace
* fix mention, implement hashtag
* lineBegin, lineEnd, refactor
* imple codeBlock, fix lineEnd
* codeBlock, mathBlock
* fix codeBlock
* fix mathBlock
* fix codeBlock
* lint
* fix inlineCode
* :rocket:
* centerTag
* fix nesting limit
* fix unicodeEmoji
* :rocket:
* search
* refactor
* seqPartial -> seqOrText
* lint
* url, urlAlt
* :rocket:
* :rocket:
* text
* fix
* link
* linkLabel state
* lint
* nesting limit for link label
* fix url bracket pair
* nest
* refactor
* refactor
* remove
* add test
* wip quote
* add quote test
* quote
* refactor
* hashtag
* refactor
* type
* type
* refactor
* lint
* url
* italicAsta, italicUnder
* italicAsta, italicUnder, mention, rethink spec
* rethink spec
* test: change implementation-dependent parts
* hashtag
* add mention test
* mention
* mention
* mention
* mention
* url
* test
* hashtag
* Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a"
This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f.
* package-lock
* Update tsconfig.json
* Update tsconfig.json
* ignore a tsd error when importing twemoji-parser regexp
* lint
* lint
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
* v0.23.0-canary.1
* readme
* update chagelog
* update changelog
* update changelog
* refactor
* update core combinators
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
|
|
|
|
An MFM parser implementation with TypeScript.
|
2021-03-27 07:18:40 +00:00
|
|
|
|
[Try it out!](https://runkit.com/npm/mfm-js)
|
2021-03-26 16:06:38 +00:00
|
|
|
|
|
2021-06-12 13:50:05 +00:00
|
|
|
|
[![Test](https://github.com/misskey-dev/mfm.js/actions/workflows/test.yml/badge.svg)](https://github.com/misskey-dev/mfm.js/actions/workflows/test.yml)
|
2021-06-26 14:48:46 +00:00
|
|
|
|
[![codecov](https://codecov.io/gh/misskey-dev/mfm.js/branch/develop/graph/badge.svg?token=irAWFiHK8T)](https://codecov.io/gh/misskey-dev/mfm.js)
|
|
|
|
|
|
2021-03-26 16:06:38 +00:00
|
|
|
|
[![NPM](https://nodei.co/npm/mfm-js.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/mfm-js)
|
2020-01-31 19:29:30 +00:00
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
```
|
2021-03-26 16:48:04 +00:00
|
|
|
|
npm i mfm-js
|
2020-01-31 19:29:30 +00:00
|
|
|
|
```
|
|
|
|
|
|
2020-02-16 14:27:25 +00:00
|
|
|
|
## Usage
|
2021-06-26 15:00:09 +00:00
|
|
|
|
Please see [docs](./docs/index.md) for the detail.
|
2021-03-28 06:51:42 +00:00
|
|
|
|
|
2021-06-26 15:00:09 +00:00
|
|
|
|
TypeScript:
|
2020-02-16 14:27:25 +00:00
|
|
|
|
```ts
|
2021-03-26 16:48:04 +00:00
|
|
|
|
import * as mfm from 'mfm-js';
|
2020-02-16 14:27:25 +00:00
|
|
|
|
|
2021-03-26 15:34:01 +00:00
|
|
|
|
const inputText =
|
2021-03-20 15:36:54 +00:00
|
|
|
|
`<center>
|
2021-04-18 06:02:16 +00:00
|
|
|
|
Hello $[tada everynyan! 🎉]
|
2021-03-20 15:36:54 +00:00
|
|
|
|
|
2021-03-26 15:34:01 +00:00
|
|
|
|
I'm @ai, A bot of misskey!
|
2021-03-20 15:36:54 +00:00
|
|
|
|
|
|
|
|
|
https://github.com/syuilo/ai
|
|
|
|
|
</center>`;
|
|
|
|
|
|
2022-06-07 14:41:09 +00:00
|
|
|
|
// Generate a MFM tree from the full MFM text.
|
2021-03-26 15:34:01 +00:00
|
|
|
|
const mfmTree = mfm.parse(inputText);
|
|
|
|
|
|
2022-06-07 14:41:09 +00:00
|
|
|
|
// Generate a MFM tree from the simple MFM text.
|
|
|
|
|
const simpleMfmTree = mfm.parseSimple('I like the hot soup :soup:');
|
2021-03-26 15:34:01 +00:00
|
|
|
|
|
|
|
|
|
// Reverse to a MFM text from the MFM tree.
|
|
|
|
|
const text = mfm.toString(mfmTree);
|
2020-02-24 13:27:01 +00:00
|
|
|
|
|
2020-02-16 14:27:25 +00:00
|
|
|
|
```
|
|
|
|
|
|
2021-03-26 16:06:38 +00:00
|
|
|
|
## Develop
|
2020-02-16 14:27:25 +00:00
|
|
|
|
### 1. Clone
|
|
|
|
|
```
|
2021-03-26 14:20:12 +00:00
|
|
|
|
git clone https://github.com/misskey-dev/mfm.js.git
|
2020-02-16 14:27:25 +00:00
|
|
|
|
```
|
|
|
|
|
|
2021-03-17 06:24:33 +00:00
|
|
|
|
### 2. Install packages
|
2020-01-31 19:29:30 +00:00
|
|
|
|
```
|
2021-03-26 14:20:12 +00:00
|
|
|
|
cd mfm.js
|
2021-03-17 06:24:33 +00:00
|
|
|
|
npm i
|
2020-01-31 19:29:30 +00:00
|
|
|
|
```
|
|
|
|
|
|
2021-03-17 06:24:33 +00:00
|
|
|
|
### 3. Build
|
2020-01-31 19:29:30 +00:00
|
|
|
|
```
|
2021-03-17 06:24:33 +00:00
|
|
|
|
npm run build
|
2020-01-31 19:29:30 +00:00
|
|
|
|
```
|
|
|
|
|
|
2021-03-17 06:24:33 +00:00
|
|
|
|
### Use the interactive CLI parser
|
2021-04-15 09:21:34 +00:00
|
|
|
|
full parser:
|
2020-01-31 19:29:30 +00:00
|
|
|
|
```
|
2020-02-20 03:31:56 +00:00
|
|
|
|
npm run parse
|
2020-01-31 19:29:30 +00:00
|
|
|
|
```
|
2020-02-16 14:27:25 +00:00
|
|
|
|
|
2022-06-07 14:41:09 +00:00
|
|
|
|
simple parser:
|
2021-04-15 09:21:34 +00:00
|
|
|
|
```
|
2022-06-07 14:41:09 +00:00
|
|
|
|
npm run parse-simple
|
2021-04-15 09:21:34 +00:00
|
|
|
|
```
|
|
|
|
|
|
2020-02-16 14:27:25 +00:00
|
|
|
|
## License
|
2021-06-26 15:00:09 +00:00
|
|
|
|
This software is released under the [MIT License](LICENSE).
|