From 60be20a783a094e55f5ffbc3276fa47ebe04a3f0 Mon Sep 17 00:00:00 2001 From: Evian-Zhang Date: Mon, 3 Aug 2020 09:49:01 +0800 Subject: [PATCH 1/2] allow space in SUMMARY.md's link destination --- src/book/summary.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/book/summary.rs b/src/book/summary.rs index 4782eb84..96ba757d 100644 --- a/src/book/summary.rs +++ b/src/book/summary.rs @@ -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", " ").replace("+", " "); let link_content = collect_events!(self.stream, end Tag::Link(..)); let name = stringify_events(link_content); @@ -947,4 +948,35 @@ 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)\n- [test3](<./test link3.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(), + }), + SummaryItem::Link(Link { + name: String::from("test3"), + location: Some(PathBuf::from("./test link3.md")), + number: Some(SectionNumber(vec![3])), + 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); + } } From 9d5c454e47f03c61baf3856e4564c4cccf3d10b1 Mon Sep 17 00:00:00 2001 From: Evian-Zhang Date: Sat, 8 Aug 2020 15:13:22 +0800 Subject: [PATCH 2/2] delete '+' replacement and use cargo fmt to format --- src/book/summary.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/book/summary.rs b/src/book/summary.rs index 96ba757d..b909629c 100644 --- a/src/book/summary.rs +++ b/src/book/summary.rs @@ -333,7 +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", " ").replace("+", " "); + let href = href.replace("%20", " "); let link_content = collect_events!(self.stream, end Tag::Link(..)); let name = stringify_events(link_content); @@ -948,10 +948,10 @@ 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)\n- [test3](<./test link3.md>)"; + let src = "- [test1](./test%20link1.md)\n- [test2](<./test link2.md>)"; let should_be = vec![ SummaryItem::Link(Link { name: String::from("test1"), @@ -965,18 +965,12 @@ mod tests { number: Some(SectionNumber(vec![2])), nested_items: Vec::new(), }), - SummaryItem::Link(Link { - name: String::from("test3"), - location: Some(PathBuf::from("./test link3.md")), - number: Some(SectionNumber(vec![3])), - 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); } }