From 58064ec6338863106574260c0643df12be5ec029 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 26 Jun 2018 18:42:00 +0900 Subject: [PATCH] MFM: Improve title syntax --- src/mfm/parse/elements/title.ts | 2 +- test/mfm.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mfm/parse/elements/title.ts b/src/mfm/parse/elements/title.ts index b89739a7c..86ce8ab47 100644 --- a/src/mfm/parse/elements/title.ts +++ b/src/mfm/parse/elements/title.ts @@ -9,7 +9,7 @@ export type TextElementTitle = { }; export default function(text: string) { - const match = text.match(/^【(.+?)】\n/); + const match = text.match(/^(【|\[)(.+?)(】|])\n/); if (!match) return null; const title = match[0]; return { diff --git a/test/mfm.ts b/test/mfm.ts index f7fa1c0f5..df0f0be04 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -115,6 +115,18 @@ describe('Text', () => { { type: 'search', content: 'a b c SEARCH', query: 'a b c'} ], tokens4); }); + + it('title', () => { + const tokens1 = analyze('【yee】\nhaw'); + assert.deepEqual( + { type: 'title', content: '【yee】\n', title: 'yee'} + , tokens1[0]); + + const tokens2 = analyze('[yee]\nhaw'); + assert.deepEqual( + { type: 'title', content: '[yee]\n', title: 'yee'} + , tokens2[0]); + }); }); describe('syntax highlighting', () => {