Skip to content
Snippets Groups Projects
Unverified Commit a5f817d8 authored by syuilo's avatar syuilo
Browse files

Fix #2744

parent 51b0244c
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......@@ -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', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment