Skip to content

Commit f5ae7c4

Browse files
authored
Merge pull request #1291 from ericonr/fix-break
summary: turn SoftBreak events into spaces.
2 parents 303db0d + dcf9462 commit f5ae7c4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/book/summary.rs

+21
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)