summaryrefslogtreecommitdiffstats
path: root/src/book
diff options
context:
space:
mode:
Diffstat (limited to 'src/book')
-rw-r--r--src/book/init.rs13
-rw-r--r--src/book/mod.rs7
-rw-r--r--src/book/summary.rs47
3 files changed, 60 insertions, 7 deletions
diff --git a/src/book/init.rs b/src/book/init.rs
index 7ae00b65..ea1911db 100644
--- a/src/book/init.rs
+++ b/src/book/init.rs
@@ -109,10 +109,9 @@ impl BookBuilder {
fn copy_across_theme(&self) -> Result<()> {
debug!("Copying theme");
- let themedir = self
- .config
- .html_config()
- .and_then(|html| html.theme)
+ let html_config = self.config.html_config().unwrap_or_default();
+ let themedir = html_config
+ .theme
.unwrap_or_else(|| self.config.book.src.join("theme"));
let themedir = self.root.join(themedir);
@@ -136,8 +135,10 @@ impl BookBuilder {
let mut chrome_css = File::create(cssdir.join("chrome.css"))?;
chrome_css.write_all(theme::CHROME_CSS)?;
- let mut print_css = File::create(cssdir.join("print.css"))?;
- print_css.write_all(theme::PRINT_CSS)?;
+ if html_config.print.enable {
+ let mut print_css = File::create(cssdir.join("print.css"))?;
+ print_css.write_all(theme::PRINT_CSS)?;
+ }
let mut variables_css = File::create(cssdir.join("variables.css"))?;
variables_css.write_all(theme::VARIABLES_CSS)?;
diff --git a/src/book/mod.rs b/src/book/mod.rs
index 71f0197f..0723578f 100644
--- a/src/book/mod.rs
+++ b/src/book/mod.rs
@@ -250,6 +250,7 @@ impl MDBook {
// Index Preprocessor is disabled so that chapter paths continue to point to the
// actual markdown files.
+ let mut failed = false;
for item in book.iter() {
if let BookItem::Chapter(ref ch) = *item {
let chapter_path = match ch.path {
@@ -282,7 +283,8 @@ impl MDBook {
let output = cmd.output()?;
if !output.status.success() {
- bail!(
+ failed = true;
+ error!(
"rustdoc returned an error:\n\
\n--- stdout\n{}\n--- stderr\n{}",
String::from_utf8_lossy(&output.stdout),
@@ -291,6 +293,9 @@ impl MDBook {
}
}
}
+ if failed {
+ bail!("One or more tests failed");
+ }
Ok(())
}
diff --git a/src/book/summary.rs b/src/book/summary.rs
index 996913a0..b909629c 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", " ");
let link_content = collect_events!(self.stream, end Tag::Link(..));
let name = stringify_events(link_content);
@@ -569,6 +570,7 @@ fn stringify_events(events: Vec<Event<'_>>) -> String {
.into_iter()
.filter_map(|t| match t {
Event::Text(text) | Event::Code(text) => Some(text.into_string()),
+ Event::SoftBreak => Some(String::from(" ")),
_ => None,
})
.collect()
@@ -926,4 +928,49 @@ mod tests {
assert_eq!(got, should_be);
}
+
+ /// Regression test for https://github.com/rust-lang/mdBook/issues/1218
+ /// Ensure chapter names spread across multiple lines have spaces between all the words.
+ #[test]
+ fn add_space_for_multi_line_chapter_names() {
+ let src = "- [Chapter\ntitle](./chapter.md)";
+ let should_be = vec![SummaryItem::Link(Link {
+ name: String::from("Chapter title"),
+ location: Some(PathBuf::from("./chapter.md")),
+ number: Some(SectionNumber(vec![1])),
+ 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);
+ }
+
+ #[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);
+ }
}