Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
marihachi committed Jul 22, 2022
2 parents 1137458 + 8cfb949 commit 024d2b9
Show file tree
Hide file tree
Showing 20 changed files with 4,100 additions and 5,519 deletions.
26 changes: 14 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@
-->

## 0.22.1
## 0.23.0

npm: https://www.npmjs.com/package/mfm-js/v/0.22.1
### Features
- Add Plain syntax (#101)

### Improvements
- The parser is now implemented in TypeScript! 🎉 (#92)
- Disable all syntax when nesting limited (#90)

### Changes
- Rename existing plain series (#113):
- parsePlain -> parseSimple
- MfmPlainNode -> MfmSimpleNode

## 0.22.1

### Improvements
- Removes a unnecessary built file
Expand All @@ -35,8 +47,6 @@ npm: https://www.npmjs.com/package/mfm-js/v/0.22.0

## 0.21.0

npm: https://www.npmjs.com/package/mfm-js/v/0.21.0

### Features
- Supports nestLimit option. (#87, #91)

Expand All @@ -49,8 +59,6 @@ npm: https://www.npmjs.com/package/mfm-js/v/0.21.0

## 0.20.0

npm: https://www.npmjs.com/package/mfm-js/v/0.20.0

### Features
- Add tag syntaxes of bold `<b></b>` and strikethrough `<s></s>`. (#76)
- Supports whitelisting of MFM function names. (#77)
Expand All @@ -66,22 +74,16 @@ npm: https://www.npmjs.com/package/mfm-js/v/0.20.0

## 0.19.0

npm: https://www.npmjs.com/package/mfm-js/v/0.19.0

### Improvements
- Ignores a blank line after quote lines. (#61)

## 0.18.0

npm: https://www.npmjs.com/package/mfm-js/v/0.18.0

### Improvements
- Twemoji v13.1 is supported.

## 0.17.0

npm: https://www.npmjs.com/package/mfm-js/v/0.17.0

### Improvements
- Improves syntax of inline code.
- Improves syntax of url.
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mfm.js
An MFM parser implementation with PEG.js.
An MFM parser implementation with TypeScript.
[Try it out!](https://runkit.com/npm/mfm-js)

[![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)
Expand Down Expand Up @@ -28,11 +28,11 @@ I'm @ai, A bot of misskey!
https://github.com/syuilo/ai
</center>`;

// Generate a MFM tree from the MFM text.
// Generate a MFM tree from the full MFM text.
const mfmTree = mfm.parse(inputText);

// Generate a MFM tree from the MFM plain text.
const plainMfmTree = mfm.parsePlain('I like the hot soup :soup:​');
// Generate a MFM tree from the simple MFM text.
const simpleMfmTree = mfm.parseSimple('I like the hot soup :soup:​');

// Reverse to a MFM text from the MFM tree.
const text = mfm.toString(mfmTree);
Expand Down Expand Up @@ -62,9 +62,9 @@ full parser:
npm run parse
```

plain parser:
simple parser:
```
npm run parse-plain
npm run parse-simple
```

## License
Expand Down
4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ console.log(JSON.stringify(nodes));
// => [{"type":"bold","children":[{"type":"text","props":{"text":"<s>cannot nest</s>"}}]}]
```

## parsePlain API
## parseSimple API
入力文字列からノードツリーを生成します。
絵文字コードとUnicode絵文字を利用可能です。

例:
```ts
const nodes = mfm.parsePlain('Hello :surprised_ai:');
const nodes = mfm.parseSimple('Hello :surprised_ai:');
console.log(JSON.stringify(nodes));
// => [{"type":"text","props":{"text":"Hello "}},{"type":"emojiCode","props":{"name":"surprised_ai"}}]
```
Expand Down
6 changes: 3 additions & 3 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ _italic_
構文2,3のみ:
※1つ目の`*``_`を開始記号と呼ぶ。
- 内容には`[a-z0-9 \t]i`にマッチする文字が使用できる。
- 開始記号の前の文字が(無い、改行、半角スペース、[a-zA-Z0-9]に一致しない)のいずれかの時にイタリック文字として判定される
- 開始記号の前の文字が`[a-z0-9]i`に一致しない時にイタリック文字として判定される

## ノード
```js
Expand Down Expand Up @@ -402,7 +402,7 @@ _italic_
```

## 詳細
- 最初の`@`の前の文字が(改行、スペース、無し、[a-zA-Z0-9]に一致しない)のいずれかの場合にメンションとして認識する
- 最初の`@`の前の文字が`[a-z0-9]i`に一致しない場合にメンションとして認識する

### ユーザ名
- 1文字以上。
Expand Down Expand Up @@ -451,7 +451,7 @@ _italic_
- 内容には半角スペース、全角スペース、改行、タブ文字を含めることができない。
- 内容には`.` `,` `!` `?` `'` `"` `#` `:` `/` `` `` `<` `>` `` `` `(` `)` `` `` `` `` を含めることができない。
- 括弧は対になっている時のみ内容に含めることができる。対象: `()` `[]` `「」` `()`
- `#`の前の文字が(改行、スペース、無し、[a-zA-Z0-9]に一致しない)のいずれかの場合にハッシュタグとして認識する
- `#`の前の文字が`[a-z0-9]i`に一致しない場合にハッシュタグとして認識する
- 内容が数字のみの場合はハッシュタグとして認識しない。

## ノード
Expand Down
23 changes: 17 additions & 6 deletions etc/mfm-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export type MfmHashtag = {
};

// @public (undocumented)
export type MfmInline = MfmUnicodeEmoji | MfmEmojiCode | MfmBold | MfmSmall | MfmItalic | MfmStrike | MfmInlineCode | MfmMathInline | MfmMention | MfmHashtag | MfmUrl | MfmLink | MfmFn | MfmText;
export type MfmInline = MfmUnicodeEmoji | MfmEmojiCode | MfmBold | MfmSmall | MfmItalic | MfmStrike | MfmInlineCode | MfmMathInline | MfmMention | MfmHashtag | MfmUrl | MfmLink | MfmFn | MfmPlain | MfmText;

// @public (undocumented)
export type MfmInlineCode = {
Expand Down Expand Up @@ -165,6 +165,13 @@ export type MfmMention = {
// @public (undocumented)
export type MfmNode = MfmBlock | MfmInline;

// @public (undocumented)
export type MfmPlain = {
type: 'plain';
props?: Record<string, unknown>;
children: MfmText[];
};

// @public (undocumented)
export type MfmQuote = {
type: 'quote';
Expand All @@ -182,6 +189,9 @@ export type MfmSearch = {
children?: [];
};

// @public (undocumented)
export type MfmSimpleNode = MfmUnicodeEmoji | MfmEmojiCode | MfmText;

// @public (undocumented)
export type MfmSmall = {
type: 'small';
Expand Down Expand Up @@ -225,21 +235,22 @@ export type MfmUrl = {
};

// @public (undocumented)
export const N_URL: (value: string, brackets?: boolean | undefined) => NodeType<'url'>;
export const N_URL: (value: string, brackets?: boolean) => NodeType<'url'>;

// @public (undocumented)
export type NodeType<T extends MfmNode['type']> = T extends 'quote' ? MfmQuote : T extends 'search' ? MfmSearch : T extends 'blockCode' ? MfmCodeBlock : T extends 'mathBlock' ? MfmMathBlock : T extends 'center' ? MfmCenter : T extends 'unicodeEmoji' ? MfmUnicodeEmoji : T extends 'emojiCode' ? MfmEmojiCode : T extends 'bold' ? MfmBold : T extends 'small' ? MfmSmall : T extends 'italic' ? MfmItalic : T extends 'strike' ? MfmStrike : T extends 'inlineCode' ? MfmInlineCode : T extends 'mathInline' ? MfmMathInline : T extends 'mention' ? MfmMention : T extends 'hashtag' ? MfmHashtag : T extends 'url' ? MfmUrl : T extends 'link' ? MfmLink : T extends 'fn' ? MfmFn : T extends 'text' ? MfmText : never;
export type NodeType<T extends MfmNode['type']> = T extends 'quote' ? MfmQuote : T extends 'search' ? MfmSearch : T extends 'blockCode' ? MfmCodeBlock : T extends 'mathBlock' ? MfmMathBlock : T extends 'center' ? MfmCenter : T extends 'unicodeEmoji' ? MfmUnicodeEmoji : T extends 'emojiCode' ? MfmEmojiCode : T extends 'bold' ? MfmBold : T extends 'small' ? MfmSmall : T extends 'italic' ? MfmItalic : T extends 'strike' ? MfmStrike : T extends 'inlineCode' ? MfmInlineCode : T extends 'mathInline' ? MfmMathInline : T extends 'mention' ? MfmMention : T extends 'hashtag' ? MfmHashtag : T extends 'url' ? MfmUrl : T extends 'link' ? MfmLink : T extends 'fn' ? MfmFn : T extends 'plain' ? MfmPlain : T extends 'text' ? MfmText : never;

// @public (undocumented)
export function parse(input: string, opts?: Partial<{
fnNameList: string[];
nestLimit: number;
}>): MfmNode[];

// Warning: (ae-forgotten-export) The symbol "MfmPlainNode" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function parsePlain(input: string): MfmPlainNode[];
export function parseSimple(input: string): MfmSimpleNode[];

// @public (undocumented)
export const PLAIN: (text: string) => NodeType<'plain'>;

// @public (undocumented)
export const QUOTE: (children: MfmNode[]) => NodeType<'quote'>;
Expand Down
Loading

0 comments on commit 024d2b9

Please sign in to comment.