Skip to content

Commit dcf9462

Browse files
committed
summary: turn SoftBreak events into spaces.
Summary items that had their name split into two lines ended up with the last word of one line and the first word of the next line glued together, since a space wasn't added. Added test case for it. Fixes #1218
1 parent 303db0d commit dcf9462

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/book/summary.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ fn stringify_events(events: Vec<Event<'_>>) -> String {
569569
.into_iter()
570570
.filter_map(|t| match t {
571571
Event::Text(text) | Event::Code(text) => Some(text.into_string()),
572+
Event::SoftBreak => Some(String::from(" ")),
572573
_ => None,
573574
})
574575
.collect()
@@ -926,4 +927,24 @@ mod tests {
926927

927928
assert_eq!(got, should_be);
928929
}
930+
931+
/// Regression test for https://github.com/rust-lang/mdBook/issues/1218
932+
/// Ensure chapter names spread across multiple lines have spaces between all the words.
933+
#[test]
934+
fn add_space_for_multi_line_chapter_names() {
935+
let src = "- [Chapter\ntitle](./chapter.md)";
936+
let should_be = vec![SummaryItem::Link(Link {
937+
name: String::from("Chapter title"),
938+
location: Some(PathBuf::from("./chapter.md")),
939+
number: Some(SectionNumber(vec![1])),
940+
nested_items: Vec::new(),
941+
})];
942+
943+
let mut parser = SummaryParser::new(src);
944+
let got = parser
945+
.parse_numbered(&mut 0, &mut SectionNumber::default())
946+
.unwrap();
947+
948+
assert_eq!(got, should_be);
949+
}
929950
}

0 commit comments

Comments
 (0)