Skip to content

Commit

Permalink
Merge pull request #1744 from ilslv/1743-fix-title-consuming-events
Browse files Browse the repository at this point in the history
Fix `SummaryParser::parse_title()` consuming events (#1743)
  • Loading branch information
ehuss authored Mar 27, 2022
2 parents 6cab045 + b73d02f commit 1562629
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/book/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,10 @@ impl<'a> SummaryParser<'a> {
// Skip a HTML element such as a comment line.
Some(Event::Html(_)) => {}
// Otherwise, no title.
Some(ev) => {
self.back(ev);
return None;
}
_ => return None,
}
}
Expand Down Expand Up @@ -647,6 +651,18 @@ mod tests {
assert_eq!(got, should_be);
}

#[test]
fn no_initial_title() {
let src = "[Link]()";
let mut parser = SummaryParser::new(src);

assert!(parser.parse_title().is_none());
assert!(matches!(
parser.next_event(),
Some(Event::Start(Tag::Paragraph))
));
}

#[test]
fn parse_title_with_styling() {
let src = "# My **Awesome** Summary";
Expand Down

0 comments on commit 1562629

Please sign in to comment.