1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-11-24 07:06:26 +09:00
This commit is contained in:
syuilo 2018-09-21 08:33:24 +09:00
parent 51b0244cf2
commit a5f817d896
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
2 changed files with 26 additions and 9 deletions

View File

@ -8,13 +8,20 @@ export type TextElementQuote = {
quote: string
};
export default function(text: string) {
const match = text.match(/^"([\s\S]+?)\n"/) || text.match(/^>([\s\S]+?)\n\n/) || text.match(/^\n>([\s\S]+?)\n\n/) || text.match(/^>([\s\S]+?)$/);
export default function(text: string, index: number) {
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;
const quote = match[0];
const quote = match[1]
.split('\n')
.map(line => line.replace(/^>+/g, '').trim())
.join('\n');
return {
type: 'quote',
content: quote,
quote: match[1].trim(),
content: match[0],
quote: quote,
} as TextElementQuote;
}

View File

@ -88,17 +88,27 @@ describe('Text', () => {
});
it('quote', () => {
const tokens1 = analyze('> foo\nbar\baz');
const tokens1 = analyze('> foo\nbar\nbaz');
assert.deepEqual([
{ type: 'quote', content: '> foo\nbar\baz', quote: 'foo\nbar\baz' }
{ type: 'quote', content: '> foo\nbar\nbaz', quote: 'foo\nbar\nbaz' }
], tokens1);
const tokens2 = analyze('before\n> foo\nbar\baz\n\nafter');
const tokens2 = analyze('before\n> foo\nbar\nbaz\n\nafter');
assert.deepEqual([
{ 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' }
], 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', () => {