From cd28504dd8e4623ed864de2ad76e88e1022b08b1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 5 Aug 2018 12:33:51 +0900 Subject: Add new MFM syntax --- src/mfm/parse/elements/motion.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/mfm/parse/elements/motion.ts (limited to 'src/mfm/parse/elements') diff --git a/src/mfm/parse/elements/motion.ts b/src/mfm/parse/elements/motion.ts new file mode 100644 index 0000000000..555a989750 --- /dev/null +++ b/src/mfm/parse/elements/motion.ts @@ -0,0 +1,20 @@ +/** + * Motion + */ + +export type TextElementMotion = { + type: 'motion' + content: string + motion: string +}; + +export default function(text: string) { + const match = text.match(/^\(\(\((.+?)\)\)\)/); + if (!match) return null; + const motion = match[0]; + return { + type: 'motion', + content: motion, + motion: match[1] + } as TextElementMotion; +} -- cgit v1.2.3-freya From b68f74f39c7a8c86fdeecb5d298cfe7c8d98ebf2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 5 Aug 2018 12:33:55 +0900 Subject: typo --- src/mfm/parse/elements/big.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mfm/parse/elements') diff --git a/src/mfm/parse/elements/big.ts b/src/mfm/parse/elements/big.ts index ca798986e9..8e39c75a55 100644 --- a/src/mfm/parse/elements/big.ts +++ b/src/mfm/parse/elements/big.ts @@ -1,5 +1,5 @@ /** - * Bold + * Big */ export type TextElementBig = { -- cgit v1.2.3-freya From d0926a3ba1e4666cad7ffb4aac4ff5fdc3a1476b Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 5 Aug 2018 23:56:08 +0900 Subject: MFMの((()))構文が顔文字と競合する対策としてタグ形式の構文も追加 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mfm/parse/elements/motion.ts | 2 +- test/mfm.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src/mfm/parse/elements') diff --git a/src/mfm/parse/elements/motion.ts b/src/mfm/parse/elements/motion.ts index 555a989750..9e7370e071 100644 --- a/src/mfm/parse/elements/motion.ts +++ b/src/mfm/parse/elements/motion.ts @@ -9,7 +9,7 @@ export type TextElementMotion = { }; export default function(text: string) { - const match = text.match(/^\(\(\((.+?)\)\)\)/); + const match = text.match(/^\(\(\((.+?)\)\)\)/) || text.match(/^(.+?)<\/motion>/); if (!match) return null; const motion = match[0]; return { diff --git a/test/mfm.ts b/test/mfm.ts index 652a6e9820..697d92e170 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -40,11 +40,17 @@ describe('Text', () => { }); it('motion', () => { - const tokens = analyze('(((Strawberry))) Pasta'); + const tokens1 = analyze('(((Strawberry))) Pasta'); assert.deepEqual([ { type: 'motion', content: '(((Strawberry)))', motion: 'Strawberry' }, { type: 'text', content: ' Pasta' } - ], tokens); + ], tokens1); + + const tokens2 = analyze('Strawberry Pasta'); + assert.deepEqual([ + { type: 'motion', content: 'Strawberry', motion: 'Strawberry' }, + { type: 'text', content: ' Pasta' } + ], tokens2); }); it('mention', () => { -- cgit v1.2.3-freya