Fix #2744
This commit is contained in:
parent
51b0244cf2
commit
a5f817d896
|
@ -8,13 +8,20 @@ export type TextElementQuote = {
|
||||||
quote: string
|
quote: string
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function(text: string) {
|
export default function(text: string, index: number) {
|
||||||
const match = text.match(/^"([\s\S]+?)\n"/) || text.match(/^>([\s\S]+?)\n\n/) || text.match(/^\n>([\s\S]+?)\n\n/) || text.match(/^>([\s\S]+?)$/);
|
const match = text.match(/^"([\s\S]+?)\n"/) || text.match(/^\n>([\s\S]+?)(\n\n|$)/) ||
|
||||||
|
(index == 0 ? text.match(/^>([\s\S]+?)(\n\n|$)/) : null);
|
||||||
|
|
||||||
if (!match) return null;
|
if (!match) return null;
|
||||||
const quote = match[0];
|
|
||||||
|
const quote = match[1]
|
||||||
|
.split('\n')
|
||||||
|
.map(line => line.replace(/^>+/g, '').trim())
|
||||||
|
.join('\n');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'quote',
|
type: 'quote',
|
||||||
content: quote,
|
content: match[0],
|
||||||
quote: match[1].trim(),
|
quote: quote,
|
||||||
} as TextElementQuote;
|
} as TextElementQuote;
|
||||||
}
|
}
|
||||||
|
|
18
test/mfm.ts
18
test/mfm.ts
|
@ -88,17 +88,27 @@ describe('Text', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('quote', () => {
|
it('quote', () => {
|
||||||
const tokens1 = analyze('> foo\nbar\baz');
|
const tokens1 = analyze('> foo\nbar\nbaz');
|
||||||
assert.deepEqual([
|
assert.deepEqual([
|
||||||
{ type: 'quote', content: '> foo\nbar\baz', quote: 'foo\nbar\baz' }
|
{ type: 'quote', content: '> foo\nbar\nbaz', quote: 'foo\nbar\nbaz' }
|
||||||
], tokens1);
|
], tokens1);
|
||||||
|
|
||||||
const tokens2 = analyze('before\n> foo\nbar\baz\n\nafter');
|
const tokens2 = analyze('before\n> foo\nbar\nbaz\n\nafter');
|
||||||
assert.deepEqual([
|
assert.deepEqual([
|
||||||
{ type: 'text', content: 'before' },
|
{ type: 'text', content: 'before' },
|
||||||
{ type: 'quote', content: '\n> foo\nbar\baz\n\n', quote: 'foo\nbar\baz' },
|
{ type: 'quote', content: '\n> foo\nbar\nbaz\n\n', quote: 'foo\nbar\nbaz' },
|
||||||
{ type: 'text', content: 'after' }
|
{ type: 'text', content: 'after' }
|
||||||
], tokens2);
|
], tokens2);
|
||||||
|
|
||||||
|
const tokens3 = analyze('piyo> foo\nbar\nbaz');
|
||||||
|
assert.deepEqual([
|
||||||
|
{ type: 'text', content: 'piyo> foo\nbar\nbaz' }
|
||||||
|
], tokens3);
|
||||||
|
|
||||||
|
const tokens4 = analyze('> foo\n> bar\n> baz');
|
||||||
|
assert.deepEqual([
|
||||||
|
{ type: 'quote', content: '> foo\n> bar\n> baz', quote: 'foo\nbar\nbaz' }
|
||||||
|
], tokens4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('url', () => {
|
it('url', () => {
|
||||||
|
|
Loading…
Reference in New Issue