sfm-js/README.md

67 lines
1.1 KiB
Markdown
Raw Permalink Normal View History

2023-12-22 00:52:03 +00:00
# sfm.js
An SFM parser implementation with fixes based on MFM
2020-01-31 19:29:30 +00:00
## Installation
```
2023-12-22 00:52:03 +00:00
npm config set @sharkey:registry https://git.joinsharkey.org/api/packages/Sharkey/npm/
npm i @sharkey/sfm-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
2023-12-22 00:52:03 +00:00
import * as mfm from '@sharkey/sfm-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>`;
// Generate a MFM tree from the full MFM text.
2021-03-26 15:34:01 +00:00
const mfmTree = mfm.parse(inputText);
// 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
```
2023-12-22 00:52:03 +00:00
git clone https://git.joinsharkey.org/Sharkey/sfm.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
```
2023-12-22 00:52:03 +00:00
cd sfm.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
simple parser:
2021-04-15 09:21:34 +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).