diff --git a/src/mfm/language.ts b/src/mfm/language.ts index 75a2baaab9a00aaa4d09f29cbd2cf578503bc358..5d5e35fbfd901086b8b7b98e894e8d0917332d00 100644 --- a/src/mfm/language.ts +++ b/src/mfm/language.ts @@ -6,8 +6,8 @@ import { toUnicode } from 'punycode'; import { emojiRegex } from '../misc/emoji-regex'; export function removeOrphanedBrackets(s: string): string { - const openBrackets = ['(', '「']; - const closeBrackets = [')', 'ã€']; + const openBrackets = ['(', '「', '[']; + const closeBrackets = [')', 'ã€', ']']; const xs = cumulativeSum(s.split('').map(c => { if (openBrackets.includes(c)) return 1; if (closeBrackets.includes(c)) return -1; diff --git a/test/mfm.ts b/test/mfm.ts index be8b65264acb0d46f1213bab7957d41e67b62f3d..8ef72c9f8a264debde26296600323c086b2214e6 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -843,6 +843,15 @@ describe('MFM', () => { ]); }); + it('ignore parent []', () => { + const tokens = parse('[https://example.com/foo]'); + assert.deepStrictEqual(tokens, [ + text('['), + leaf('url', { url: 'https://example.com/foo' }), + text(']') + ]); + }); + it('ignore parent brackets 2', () => { const tokens = parse('(foo https://example.com/foo)'); assert.deepStrictEqual(tokens, [