Fix MFM parsing: Ignore parent [] of URL
This commit is contained in:
parent
10677b57d4
commit
76693138d3
|
@ -6,8 +6,8 @@ import { toUnicode } from 'punycode';
|
||||||
import { emojiRegex } from '../misc/emoji-regex';
|
import { emojiRegex } from '../misc/emoji-regex';
|
||||||
|
|
||||||
export function removeOrphanedBrackets(s: string): string {
|
export function removeOrphanedBrackets(s: string): string {
|
||||||
const openBrackets = ['(', '「'];
|
const openBrackets = ['(', '「', '['];
|
||||||
const closeBrackets = [')', '」'];
|
const closeBrackets = [')', '」', ']'];
|
||||||
const xs = cumulativeSum(s.split('').map(c => {
|
const xs = cumulativeSum(s.split('').map(c => {
|
||||||
if (openBrackets.includes(c)) return 1;
|
if (openBrackets.includes(c)) return 1;
|
||||||
if (closeBrackets.includes(c)) return -1;
|
if (closeBrackets.includes(c)) return -1;
|
||||||
|
|
|
@ -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', () => {
|
it('ignore parent brackets 2', () => {
|
||||||
const tokens = parse('(foo https://example.com/foo)');
|
const tokens = parse('(foo https://example.com/foo)');
|
||||||
assert.deepStrictEqual(tokens, [
|
assert.deepStrictEqual(tokens, [
|
||||||
|
|
Loading…
Reference in New Issue