diff options
| author | ibrokemypie <ibrokemypie@bastardi.net> | 2019-01-20 20:00:55 +1100 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2019-01-20 18:00:55 +0900 |
| commit | 53481accf13cbb6227d12e98542b0f314b2a586e (patch) | |
| tree | 6c16f36f30a81846cac7711d84ad23d3c26f6011 | |
| parent | Update CHANGELOG.md (diff) | |
| download | sharkey-53481accf13cbb6227d12e98542b0f314b2a586e.tar.gz sharkey-53481accf13cbb6227d12e98542b0f314b2a586e.tar.bz2 sharkey-53481accf13cbb6227d12e98542b0f314b2a586e.zip | |
Add double underscore syntax for bold markdown (#3733)
* Add double underscore syntax for bold markdown
see https://github.com/syuilo/misskey/pull/3732
this allows bold text through either **text** or __text__
* Add tests for underscore bold mfm syntax
| -rw-r--r-- | src/mfm/parser.ts | 2 | ||||
| -rw-r--r-- | test/mfm.ts | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/mfm/parser.ts b/src/mfm/parser.ts index 2ab38d97a8..c271b62e23 100644 --- a/src/mfm/parser.ts +++ b/src/mfm/parser.ts @@ -154,7 +154,7 @@ const mfm = P.createLanguage({ //#region Bold bold: r => - P.regexp(/\*\*([\s\S]+?)\*\*/, 1) + P.regexp(/(\*\*|__)([\s\S]+?)\1/, 2) .map(x => createTree('bold', P.alt( r.strike, r.italic, diff --git a/test/mfm.ts b/test/mfm.ts index b681ed1d01..bacce017c2 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -177,6 +177,29 @@ describe('MFM', () => { text('bar'), ]); }); + + it('with underscores', () => { + const tokens = analyze('__foo__'); + assert.deepStrictEqual(tokens, [ + tree('bold', [ + text('foo') + ], {}), + ]); + }); + + it('mixed syntax', () => { + const tokens = analyze('**foo__'); + assert.deepStrictEqual(tokens, [ + text('**foo__'), + ]); + }); + + it('mixed syntax', () => { + const tokens = analyze('__foo**'); + assert.deepStrictEqual(tokens, [ + text('__foo**'), + ]); + }); }); it('big', () => { |