Skip to content

Commit

Permalink
Merge pull request #1293 from Evian-Zhang/master
Browse files Browse the repository at this point in the history
allow space in SUMMARY.md's link destination
  • Loading branch information
ehuss committed Aug 8, 2020
2 parents a00e7d1 + 9d5c454 commit 3d44553
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/book/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ impl<'a> SummaryParser<'a> {

/// Finishes parsing a link once the `Event::Start(Tag::Link(..))` has been opened.
fn parse_link(&mut self, href: String) -> Link {
let href = href.replace("%20", " ");
let link_content = collect_events!(self.stream, end Tag::Link(..));
let name = stringify_events(link_content);

Expand Down Expand Up @@ -947,4 +948,29 @@ mod tests {

assert_eq!(got, should_be);
}

#[test]
fn allow_space_in_link_destination() {
let src = "- [test1](./test%20link1.md)\n- [test2](<./test link2.md>)";
let should_be = vec![
SummaryItem::Link(Link {
name: String::from("test1"),
location: Some(PathBuf::from("./test link1.md")),
number: Some(SectionNumber(vec![1])),
nested_items: Vec::new(),
}),
SummaryItem::Link(Link {
name: String::from("test2"),
location: Some(PathBuf::from("./test link2.md")),
number: Some(SectionNumber(vec![2])),
nested_items: Vec::new(),
}),
];
let mut parser = SummaryParser::new(src);
let got = parser
.parse_numbered(&mut 0, &mut SectionNumber::default())
.unwrap();

assert_eq!(got, should_be);
}
}

0 comments on commit 3d44553

Please sign in to comment.