diff --git a/CHANGELOG.md b/CHANGELOG.md index 54cc50c..ee44cc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ --> +## 0.23.1 +### Improvements +- improve emoji code parsing + ## 0.23.0 ### Features @@ -35,8 +39,6 @@ ## 0.22.0 -npm: https://www.npmjs.com/package/mfm-js/v/0.22.0 - ### Features - Unicode emoji supports Unicode 14.0 emoji (#109) diff --git a/docs/syntax.md b/docs/syntax.md index 529bfe2..29ae576 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -546,7 +546,7 @@ silent=true ``` ## 詳細 -- リンクラベルには再度InlineParserを適用する。ただし、リンクラベルではURL、リンク、メンションは使用できない。 +- 表示テキストには再度InlineParserを適用する。ただし、表示テキストではURL、リンク、メンションは使用できない。 ## ノード ```js diff --git a/package-lock.json b/package-lock.json index 48e2837..423e834 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mfm-js", - "version": "0.23.0", + "version": "0.23.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mfm-js", - "version": "0.23.0", + "version": "0.23.1", "license": "MIT", "dependencies": { "twemoji-parser": "14.0.0" diff --git a/package.json b/package.json index bc53c3c..d79f770 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mfm-js", - "version": "0.23.0", + "version": "0.23.1", "description": "An MFM parser implementation with TypeScript", "main": "./built/index.js", "types": "./built/index.d.ts", @@ -39,6 +39,7 @@ "twemoji-parser": "14.0.0" }, "files": [ - "built" + "built", + "CHANGELOG.md" ] } diff --git a/src/internal/parser.ts b/src/internal/parser.ts index 3cca5ea..3d1a04f 100644 --- a/src/internal/parser.ts +++ b/src/internal/parser.ts @@ -626,12 +626,15 @@ export const language = P.createLanguage({ }, emojiCode: r => { + const side = P.notMatch(P.regexp(/[a-z0-9]/i)); const mark = P.str(':'); return P.seq([ + P.alt([P.lineBegin, side]), mark, P.regexp(/[a-z0-9_+-]+/i), mark, - ], 1).map(name => M.EMOJI_CODE(name as string)); + P.alt([P.lineEnd, side]), + ], 2).map(name => M.EMOJI_CODE(name as string)); }, link: r => { diff --git a/test/parser.ts b/test/parser.ts index 6a2393f..77a7a41 100644 --- a/test/parser.ts +++ b/test/parser.ts @@ -34,7 +34,19 @@ describe('SimpleParser', () => { it('between texts', () => { const input = 'foo:bar:baz'; - const output = [TEXT('foo'), EMOJI_CODE('bar'), TEXT('baz')]; + const output = [TEXT('foo:bar:baz')]; + assert.deepStrictEqual(mfm.parseSimple(input), output); + }); + + it('between texts 2', () => { + const input = '12:34:56'; + const output = [TEXT('12:34:56')]; + assert.deepStrictEqual(mfm.parseSimple(input), output); + }); + + it('between texts 3', () => { + const input = 'あ:bar:い'; + const output = [TEXT('あ'), EMOJI_CODE('bar'), TEXT('い')]; assert.deepStrictEqual(mfm.parseSimple(input), output); }); });