From daba7fe87c0fe8211a81065a5e300fdb7a36aef0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 3 Nov 2018 15:28:00 +0900 Subject: [PATCH] [MFM] Fix title syntax parsing --- src/mfm/parse/elements/title.ts | 4 ++-- test/mfm.ts | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mfm/parse/elements/title.ts b/src/mfm/parse/elements/title.ts index 86ce8ab47..789d21518 100644 --- a/src/mfm/parse/elements/title.ts +++ b/src/mfm/parse/elements/title.ts @@ -8,8 +8,8 @@ export type TextElementTitle = { title: string }; -export default function(text: string) { - const match = text.match(/^(【|\[)(.+?)(】|])\n/); +export default function(text: string, i: number) { + const match = i == 0 ? text.match(/^(【|\[)(.+?)(】|])\n/) : text.match(/^\n(【|\[)(.+?)(】|])\n/); if (!match) return null; const title = match[0]; return { diff --git a/test/mfm.ts b/test/mfm.ts index 0ef2c91bc..36232468a 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -230,6 +230,11 @@ describe('Text', () => { assert.deepEqual( { type: 'title', content: '[yee]\n', title: 'yee'} , tokens2[0]); + + const tokens3 = analyze('a [a]\nb [b]\nc [c]'); + assert.deepEqual( + { type: 'text', content: 'a [a]\nb [b]\nc [c]' } + , tokens2[0]); }); });