Skip to content

Commit d646a25

Browse files
committed
fix parser bug
1 parent fca3457 commit d646a25

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/parser.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ impl Parser {
278278
start_line: usize,
279279
end_line: usize,
280280
) -> Fallible<Vec<Card>> {
281+
let text = text.trim();
281282
let mut cards = Vec::new();
282283

283284
// The full text of the card, without cloze deletion brackets.
@@ -557,4 +558,37 @@ mod tests {
557558
assert!(result.is_err());
558559
Ok(())
559560
}
561+
562+
#[test]
563+
fn test_cloze_with_initial_blank_line() -> Fallible<()> {
564+
let input =
565+
"C:\nBuild something people want in Lisp.\n\n— [Paul Graham], [_Hackers and Painters_]";
566+
let parser = make_test_parser();
567+
let cards = parser.parse(input)?;
568+
569+
assert_eq!(cards.len(), 2);
570+
match &cards[0].content() {
571+
CardContent::Cloze { text, start, end } => {
572+
assert_eq!(
573+
text,
574+
"Build something people want in Lisp.\n\n— Paul Graham, _Hackers and Painters_"
575+
);
576+
assert_eq!(*start, 40);
577+
assert_eq!(*end, 50);
578+
}
579+
_ => panic!("Expected cloze card"),
580+
}
581+
match &cards[1].content() {
582+
CardContent::Cloze { text, start, end } => {
583+
assert_eq!(
584+
text,
585+
"Build something people want in Lisp.\n\n— Paul Graham, _Hackers and Painters_"
586+
);
587+
assert_eq!(*start, 53);
588+
assert_eq!(*end, 74);
589+
}
590+
_ => panic!("Expected cloze card"),
591+
}
592+
Ok(())
593+
}
560594
}

0 commit comments

Comments
 (0)