From 54dd6125556df59ede1084fbe63fbf342d82a450 Mon Sep 17 00:00:00 2001 From: Stephen Mwangi Date: Sun, 20 Oct 2024 11:50:57 +0300 Subject: [PATCH] fix(multiline cards): the question should start from the immediate empty line above it --- src/parser.ts | 2 +- tests/unit/parser.test.ts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/parser.ts b/src/parser.ts index b0e71f02..c748bf98 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -120,7 +120,7 @@ export function parse(text: string, options: ParserOptions): ParsedQuestionInfo[ // We've probably reached the end of a card (isEmptyLine && !options.multilineCardEndMarker) || // Empty line & we're not picking up any card - (isEmptyLine && cardText.length == 0) || + (isEmptyLine && cardType == null) || // We've reached the end of a multi line card & // we're using custom end markers hasMultilineCardEndMarker diff --git a/tests/unit/parser.test.ts b/tests/unit/parser.test.ts index 9cb6d759..17dbaaba 100644 --- a/tests/unit/parser.test.ts +++ b/tests/unit/parser.test.ts @@ -298,6 +298,40 @@ test("Test parsing of multi line reversed cards", () => { clozePatterns: [], }), ).toEqual([[CardType.MultiLineReversed, "Question\n@@@\nAnswer", 0, 2]]); + expect( + parseT( + `line 1 + + +line 2 + +Question 1? +?? +Answer to question 1 +???? +line 3 + +line 4 + +Question 2? +?? +Answer to question 2 +???? +Line 5 +`, + { + singleLineCardSeparator: ":::", + singleLineReversedCardSeparator: "::::", + multilineCardSeparator: "??", + multilineReversedCardSeparator: "???", + multilineCardEndMarker: "????", + clozePatterns: [], + }, + ), + ).toEqual([ + [CardType.MultiLineBasic, "Question 1?\n??\nAnswer to question 1", 5, 7], + [CardType.MultiLineBasic, "Question 2?\n??\nAnswer to question 2", 13, 15], + ]); // empty string or whitespace character provided expect(