From e67d14b81395d31f1076be3d754f07b0b5720c66 Mon Sep 17 00:00:00 2001
From: marihachi <marihachi0620@gmail.com>
Date: Sat, 17 Apr 2021 15:35:07 +0900
Subject: [PATCH] resolve #46

---
 src/parser.pegjs | 15 +++++++++++++--
 test/parser.ts   | 20 ++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/parser.pegjs b/src/parser.pegjs
index c48868a..6403936 100644
--- a/src/parser.pegjs
+++ b/src/parser.pegjs
@@ -85,15 +85,26 @@ block
 // block: quote
 
 quote
-	= lines:quoteLine+
+	= head:quoteMultiLine tails:quoteMultiLine+
 {
-	const children = applyParser(lines.join('\n'), 'fullParser');
+	const children = applyParser([head, ...tails].join('\n'), 'fullParser');
+	return QUOTE(children);
+}
+	/ line:quoteLine
+{
+	const children = applyParser(line, 'fullParser');
 	return QUOTE(children);
 }
 
+quoteMultiLine
+	= quoteLine / quoteEmptyLine
+
 quoteLine
 	= BEGIN ">" _? text:$(CHAR+) END { return text; }
 
+quoteEmptyLine
+	= BEGIN ">" _? END { return ''; }
+
 // block: search
 
 search
diff --git a/test/parser.ts b/test/parser.ts
index 6b564d5..9088186 100644
--- a/test/parser.ts
+++ b/test/parser.ts
@@ -89,6 +89,26 @@ describe('FullParser', () => {
 			];
 			assert.deepStrictEqual(mfm.parse(input), output);
 		});
+		it('複数行の引用ブロックでは空行を含めることができる', () => {
+			const input = `
+> abc
+>
+> 123
+`;
+			const output = [
+				QUOTE([
+					TEXT('abc\n\n123')
+				])
+			];
+			assert.deepStrictEqual(mfm.parse(input), output);
+		});
+		it('1行の引用ブロックを空行にはできない', () => {
+			const input = `> `;
+			const output = [
+				TEXT('> ')
+			];
+			assert.deepStrictEqual(mfm.parse(input), output);
+		});
 	});
 
 	describe('search', () => {
-- 
GitLab