Skip to content

Commit

Permalink
fix(multiline cards): the Qn should start from the immediate empty li…
Browse files Browse the repository at this point in the history
…ne above it (#1142)

fix(multiline cards): the question should start from the immediate empty line above it
  • Loading branch information
st3v3nmw authored Oct 20, 2024
1 parent 66c92d1 commit d5f54ed
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d5f54ed

Please sign in to comment.