diff --git a/examples/nop-preprocessor.rs b/examples/nop-preprocessor.rs index ee561e95c7..a90f237617 100644 --- a/examples/nop-preprocessor.rs +++ b/examples/nop-preprocessor.rs @@ -73,6 +73,7 @@ mod nop_lib { use super::*; /// A no-op preprocessor. + #[derive(Clone)] pub struct Nop; impl Nop { diff --git a/examples/remove-emphasis/mdbook-remove-emphasis/src/main.rs b/examples/remove-emphasis/mdbook-remove-emphasis/src/main.rs index 79f5f009f1..fdd2adf0b4 100644 --- a/examples/remove-emphasis/mdbook-remove-emphasis/src/main.rs +++ b/examples/remove-emphasis/mdbook-remove-emphasis/src/main.rs @@ -28,6 +28,7 @@ fn main() { } } +#[derive(Clone)] struct RemoveEmphasis; impl Preprocessor for RemoveEmphasis { diff --git a/guide/src/format/configuration/general.md b/guide/src/format/configuration/general.md index 40a4570132..ee0d0a2192 100644 --- a/guide/src/format/configuration/general.md +++ b/guide/src/format/configuration/general.md @@ -72,7 +72,7 @@ edition = "2015" # the default edition for code blocks ``` - **edition**: Rust edition to use by default for the code snippets. Default - is `"2015"`. Individual code blocks can be controlled with the `edition2015`, + is `"2015"`. Individual code blocks can be controlled with the `edition2015`, `edition2018` or `edition2021` annotations, such as: ~~~text diff --git a/guide/src/format/configuration/preprocessors.md b/guide/src/format/configuration/preprocessors.md index 26a786b2c3..3d5417d1d9 100644 --- a/guide/src/format/configuration/preprocessors.md +++ b/guide/src/format/configuration/preprocessors.md @@ -28,6 +28,7 @@ For information on how to create a new preprocessor, see the [Preprocessors for Preprocessors can be added by including a `preprocessor` table in `book.toml` with the name of the preprocessor. For example, if you have a preprocessor called `mdbook-example`, then you can include it with: +**book.toml** ```toml [preprocessor.example] ``` diff --git a/guide/src/format/configuration/renderers.md b/guide/src/format/configuration/renderers.md index a827d2936f..47f4f99843 100644 --- a/guide/src/format/configuration/renderers.md +++ b/guide/src/format/configuration/renderers.md @@ -144,6 +144,10 @@ The following configuration options are available: - **no-section-label:** mdBook by defaults adds numeric section labels in the table of contents column. For example, "1.", "2.1". Set this option to true to disable those labels. Defaults to `false`. +- **fold:** A subtable for configuring sidebar section-folding behavior. +- **playground:** A subtable for configuring various playground settings. +- **search:** A subtable for configuring the in-browser search functionality. + mdBook must be compiled with the `search` feature enabled (on by default). - **git-repository-url:** A url to the git repository for the book. If provided an icon link will be output in the menu bar of the book. - **git-repository-icon:** The FontAwesome icon class to use for the git @@ -157,6 +161,12 @@ The following configuration options are available: `https://bitbucket.org///src//{path}?mode=edit` where {path} will be replaced with the full path of the file in the repository. +- **redirect:** A subtable used for generating redirects when a page is moved. + The table contains key-value pairs where the key is where the redirect file + needs to be created, as an absolute path from the build directory, (e.g. + `/appendices/bibliography.html`). The value can be any valid URI the + browser should navigate to (e.g. `https://rust-lang.org/`, + `/overview.html`, or `../bibliography.html`). - **input-404:** The name of the markdown file used for missing files. The corresponding output file will be the same, with the extension replaced with `html`. Defaults to `404.md`. @@ -307,6 +317,53 @@ The `[output.html.redirect]` table provides a way to add redirects. This is useful when you move, rename, or remove a page to ensure that links to the old URL will go to the new location. ```toml +[book] +title = "Example book" +authors = ["John Doe", "Jane Doe"] +description = "The example book covers examples." + +[output.html] +theme = "my-theme" +default-theme = "light" +preferred-dark-theme = "navy" +curly-quotes = true +mathjax-support = false +copy-fonts = true +google-analytics = "UA-123456-7" +additional-css = ["custom.css", "custom2.css"] +additional-js = ["custom.js"] +no-section-label = false +git-repository-url = "https://github.com/rust-lang/mdBook" +git-repository-icon = "fa-github" +edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}" +site-url = "/example-book/" +cname = "myproject.rs" +input-404 = "not-found.md" + +[output.html.print] +enable = true + +[output.html.fold] +enable = false +level = 0 + +[output.html.playground] +editable = false +copy-js = true +line-numbers = false + +[output.html.search] +enable = true +limit-results = 30 +teaser-word-count = 30 +use-boolean-and = true +boost-title = 2 +boost-hierarchy = 1 +boost-paragraph = 1 +expand = true +heading-split-level = 3 +copy-js = true + [output.html.redirect] "/appendices/bibliography.html" = "https://rustc-dev-guide.rust-lang.org/appendix/bibliography.html" "/other-installation-methods.html" = "../infra/other-installation-methods.html" @@ -337,3 +394,20 @@ only whether it is enabled or disabled. See [the preprocessors documentation](preprocessors.md) for how to specify which preprocessors should run before the Markdown renderer. + +### Custom Renderers + +A custom renderer can be enabled by adding a `[output.foo]` table to your +`book.toml`. Similar to [preprocessors](preprocessors.md) this will +instruct `mdbook` to pass a representation of the book to `mdbook-foo` for +rendering. See the [alternative backends] chapter for more detail. + +The custom renderer has access to all the fields within its table (i.e. +anything under `[output.foo]`). mdBook checks for two common fields: + +- **command:** The command to execute for this custom renderer. Defaults to + the name of the renderer with the `mdbook-` prefix (such as `mdbook-foo`). +- **optional:** If `true`, then the command will be ignored if it is not + installed, otherwise mdBook will fail with an error. Defaults to `false`. + +[alternative backends]: ../../for_developers/backends.md diff --git a/src/book/mod.rs b/src/book/mod.rs index c5d20130ee..2b3eb01e44 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -428,6 +428,11 @@ impl MDBook { .unwrap_or_default() .theme_dir(&self.root) } + + /// Clone registered boxed preprocessors Vec + pub fn clone_preprocessors(&self) -> Vec> { + self.preprocessors.clone() + } } /// Look at the `Config` and try to figure out what renderers to use. @@ -867,6 +872,7 @@ mod tests { assert!(should_run); } + #[derive(Default, Clone)] struct BoolPreprocessor(bool); impl Preprocessor for BoolPreprocessor { fn name(&self) -> &str { diff --git a/src/cmd/test.rs b/src/cmd/test.rs index d41e9ef9eb..69f99f4095 100644 --- a/src/cmd/test.rs +++ b/src/cmd/test.rs @@ -1,7 +1,7 @@ use super::command_prelude::*; use crate::get_book_dir; use clap::builder::NonEmptyStringValueParser; -use clap::ArgAction; +use clap::{Arg, ArgAction, ArgMatches, Command}; use mdbook::errors::Result; use mdbook::MDBook; use std::path::PathBuf; diff --git a/src/config.rs b/src/config.rs index db159a45ad..fcc44ca1b6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -427,6 +427,8 @@ pub struct BookConfig { /// The direction of text in the book: Left-to-right (LTR) or Right-to-left (RTL). /// When not specified, the text direction is derived from [`BookConfig::language`]. pub text_direction: Option, + /// The book version. + pub version: Option, } impl Default for BookConfig { @@ -439,6 +441,7 @@ impl Default for BookConfig { multilingual: false, language: Some(String::from("en")), text_direction: None, + version: Some(String::from("0.0.1")), } } } @@ -823,6 +826,7 @@ mod tests { multilingual = true src = "source" language = "ja" + version = "0.0.1" [build] build-dir = "outputs" @@ -863,6 +867,7 @@ mod tests { src: PathBuf::from("source"), language: Some(String::from("ja")), text_direction: None, + version: Some(String::from("0.0.1")), }; let build_should_be = BuildConfig { build_dir: PathBuf::from("outputs"), diff --git a/src/preprocess/index.rs b/src/preprocess/index.rs index 004b7eda6e..2a15d36131 100644 --- a/src/preprocess/index.rs +++ b/src/preprocess/index.rs @@ -9,7 +9,7 @@ use once_cell::sync::Lazy; /// A preprocessor for converting file name `README.md` to `index.md` since /// `README.md` is the de facto index file in markdown-based documentation. -#[derive(Default)] +#[derive(Default, Clone)] pub struct IndexPreprocessor; impl IndexPreprocessor { diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index 87ae3af3bf..e8e0190ddb 100644 --- a/src/preprocess/links.rs +++ b/src/preprocess/links.rs @@ -9,9 +9,10 @@ use std::ops::{Bound, Range, RangeBounds, RangeFrom, RangeFull, RangeTo}; use std::path::{Path, PathBuf}; use super::{Preprocessor, PreprocessorContext}; -use crate::book::{Book, BookItem}; -use log::{error, warn}; +use crate::book::{Book, BookItem, Chapter}; +use log::{debug, error, trace, warn}; use once_cell::sync::Lazy; +use std::fmt::Debug; const ESCAPE_CHAR: char = '\\'; const MAX_LINK_NESTED_DEPTH: usize = 10; @@ -26,7 +27,7 @@ const MAX_LINK_NESTED_DEPTH: usize = 10; /// block and provides them to Rustdoc for testing. /// - `{{# playground}}` - Insert runnable Rust files /// - `{{# title}}` - Override \ of a webpage. -#[derive(Default)] +#[derive(Default, Clone)] pub struct LinkPreprocessor; impl LinkPreprocessor { @@ -45,6 +46,7 @@ impl Preprocessor for LinkPreprocessor { fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result { let src_dir = ctx.root.join(&ctx.config.book.src); + trace!("src = {:?}", &src_dir.display()); book.for_each_mut(|section: &mut BookItem| { if let BookItem::Chapter(ref mut ch) = *section { @@ -55,8 +57,15 @@ impl Preprocessor for LinkPreprocessor { .expect("All book items have a parent"); let mut chapter_title = ch.name.clone(); - let content = - replace_all(&ch.content, base, chapter_path, 0, &mut chapter_title); + // run normal link replacement by all content with 'dashed' lines inside present + let content = replace_all( + &ch.content, + base, + chapter_path, + 0, + &mut chapter_title, + false, + ); ch.content = content; if chapter_title != ch.name { ctx.chapter_titles @@ -69,6 +78,34 @@ impl Preprocessor for LinkPreprocessor { Ok(book) } + + /// Pre-process one chapter's content by supplied preprocessor + fn preprocess_chapter(&self, ctx: &PreprocessorContext, chapter: &mut Chapter) -> Result<()> { + if let Some(ref chapter_path) = chapter.path { + let src_dir = ctx.root.join(&ctx.config.book.src); + trace!("src_dir = {:?}", &src_dir.display()); + let base = chapter_path + .parent() + .map(|dir| src_dir.join(dir)) + .expect("All book items have a parent"); + + trace!("base = {:?}", &base.display()); + // replace link {{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs:print}} + // by lined content with removing # dashed lines + let mut chapter_title: String = chapter.name.clone(); + let updated_content = replace_all( + &chapter.content.clone(), + base, + chapter_path, + 0, + &mut chapter_title, + true, + ); + trace!("updated_content = {:?}", updated_content.len()); + chapter.content = updated_content; + } + Ok(()) + } } fn replace_all( @@ -77,6 +114,7 @@ fn replace_all( source: P2, depth: usize, chapter_title: &mut String, + cutoff_commented_lines: bool, ) -> String where P1: AsRef, @@ -87,14 +125,22 @@ where // we therefore have to store the difference to correct this let path = path.as_ref(); let source = source.as_ref(); + trace!( + "replace_all: path = {:?}, source={:?}", + path.display(), + source.display() + ); let mut previous_end_index = 0; let mut replaced = String::new(); for link in find_links(s) { - replaced.push_str(&s[previous_end_index..link.start_index]); + let slice_string = &s[previous_end_index..link.start_index]; + trace!("replace_all: slice_string = {:?}", slice_string); + replaced.push_str(slice_string); - match link.render_with_path(path, chapter_title) { + match link.render_with_path(path, chapter_title, cutoff_commented_lines) { Ok(new_content) => { + trace!("replace_all: new_content = {:?}", new_content); if depth < MAX_LINK_NESTED_DEPTH { if let Some(rel_path) = link.link_type.relative_path(path) { replaced.push_str(&replace_all( @@ -103,6 +149,7 @@ where source, depth + 1, chapter_title, + cutoff_commented_lines, )); } else { replaced.push_str(&new_content); @@ -129,6 +176,7 @@ where } replaced.push_str(&s[previous_end_index..]); + trace!("replaced = [{:?}]", replaced.len()); replaced } @@ -323,6 +371,7 @@ impl<'a> Link<'a> { &self, base: P, chapter_title: &mut String, + cutoff_commented_lines: bool, ) -> Result { let base = base.as_ref(); match self.link_type { @@ -330,7 +379,6 @@ impl<'a> Link<'a> { LinkType::Escaped => Ok(self.link_text[1..].to_owned()), LinkType::Include(ref pat, ref range_or_anchor) => { let target = base.join(pat); - fs::read_to_string(&target) .map(|s| match range_or_anchor { RangeOrAnchor::Range(range) => take_lines(&s, range.clone()), @@ -346,14 +394,14 @@ impl<'a> Link<'a> { } LinkType::RustdocInclude(ref pat, ref range_or_anchor) => { let target = base.join(pat); - + debug!("render_with_path: target = {:?}", &target.display()); fs::read_to_string(&target) .map(|s| match range_or_anchor { RangeOrAnchor::Range(range) => { - take_rustdoc_include_lines(&s, range.clone()) + take_rustdoc_include_lines(&s, range.clone(), cutoff_commented_lines) } RangeOrAnchor::Anchor(anchor) => { - take_rustdoc_include_anchored_lines(&s, anchor) + take_rustdoc_include_anchored_lines(&s, anchor, cutoff_commented_lines) } }) .with_context(|| { @@ -444,7 +492,10 @@ mod tests { {{#include file.rs}} << an escaped link! ```"; let mut chapter_title = "test_replace_all_escaped".to_owned(); - assert_eq!(replace_all(start, "", "", 0, &mut chapter_title), end); + assert_eq!( + replace_all(start, "", "", 0, &mut chapter_title, false), + end + ); } #[test] @@ -456,8 +507,31 @@ mod tests { # My Chapter "; let mut chapter_title = "test_set_chapter_title".to_owned(); - assert_eq!(replace_all(start, "", "", 0, &mut chapter_title), end); + assert_eq!(replace_all(start, "", "", 0, &mut chapter_title, true), end); assert_eq!(chapter_title, "My Title"); + assert_eq!( + replace_all(start, "", "", 0, &mut chapter_title, false), + end + ); + } + + #[test] + fn test_replace_all_escaped_with_cutoff() { + let start = r" + Some text over here. + ```hbs + \{{#include file.rs}} << an escaped link! + ```"; + let end = r" + Some text over here. + ```hbs + {{#include file.rs}} << an escaped link! + ```"; + let mut chapter_title = "test_replace_all_escaped_with_cutoff".to_owned(); + assert_eq!( + replace_all(start, "", "", 0, &mut chapter_title, false), + end + ); } #[test] diff --git a/src/preprocess/mod.rs b/src/preprocess/mod.rs index df01a3dbfb..a8f16fd957 100644 --- a/src/preprocess/mod.rs +++ b/src/preprocess/mod.rs @@ -8,13 +8,14 @@ mod cmd; mod index; mod links; -use crate::book::Book; +use crate::book::{Book, Chapter}; use crate::config::Config; use crate::errors::*; use serde::{Deserialize, Serialize}; use std::cell::RefCell; use std::collections::HashMap; +use std::fmt::Debug; use std::path::PathBuf; /// Extra information for a `Preprocessor` to give them more context when @@ -37,7 +38,7 @@ pub struct PreprocessorContext { impl PreprocessorContext { /// Create a new `PreprocessorContext`. - pub(crate) fn new(root: PathBuf, config: Config, renderer: String) -> Self { + pub fn new(root: PathBuf, config: Config, renderer: String) -> Self { PreprocessorContext { root, config, @@ -51,7 +52,7 @@ impl PreprocessorContext { /// An operation which is run immediately after loading a book into memory and /// before it gets rendered. -pub trait Preprocessor { +pub trait Preprocessor: PreprocessorClone { /// Get the `Preprocessor`'s name. fn name(&self) -> &str; @@ -59,6 +60,15 @@ pub trait Preprocessor { /// given to a renderer. fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result; + /// Pre-Process only one mutable chapter using context and supplied pre-processor + fn preprocess_chapter(&self, ctx: &PreprocessorContext, chapter: &mut Chapter) -> Result<()> { + println!( + "preprocess chapter: '{}' by ctx = {}", + chapter.name, ctx.renderer + ); + Ok(()) + } + /// A hint to `MDBook` whether this preprocessor is compatible with a /// particular renderer. /// @@ -67,3 +77,22 @@ pub trait Preprocessor { true } } + +/// That is the code to have ability to clone vec[Preprocessor] +/// We use for cloning vector of preprocessors and reuse inside 'mdbook-epub' +pub trait PreprocessorClone { + /// clone one boxed preprocessor + fn clone_preprocessor(&self) -> Box; +} + +impl PreprocessorClone for T { + fn clone_preprocessor(&self) -> Box { + Box::new(self.clone()) + } +} + +impl Clone for Box { + fn clone(&self) -> Box { + self.clone_preprocessor() + } +} diff --git a/src/utils/string.rs b/src/utils/string.rs index 6dafe2603a..2eac7e3711 100644 --- a/src/utils/string.rs +++ b/src/utils/string.rs @@ -1,3 +1,4 @@ +use log::trace; use once_cell::sync::Lazy; use regex::Regex; use std::ops::Bound::{Excluded, Included, Unbounded}; @@ -63,25 +64,37 @@ pub fn take_anchored_lines(s: &str, anchor: &str) -> String { /// For any lines not in the range, include them but use `#` at the beginning. This will hide the /// lines from initial display but include them when expanding the code snippet or testing with /// rustdoc. -pub fn take_rustdoc_include_lines>(s: &str, range: R) -> String { +pub fn take_rustdoc_include_lines>( + s: &str, + range: R, + cutoff_commented_lines: bool, +) -> String { let mut output = String::with_capacity(s.len()); for (index, line) in s.lines().enumerate() { if !range.contains(&index) { - output.push_str("# "); + if !cutoff_commented_lines { + // do not include 'dashed' lines (for epub format) + output.push_str("# "); + } } output.push_str(line); output.push('\n'); } output.pop(); + trace!("take_rustdoc_include_lines = {:?}", output.to_string()); output } /// Keep lines between the anchor comments specified as-is. /// For any lines not between the anchors, include them but use `#` at the beginning. This will /// hide the lines from initial display but include them when expanding the code snippet or testing -/// with rustdoc. -pub fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str) -> String { +/// with rustdoc. The cutoff_commented_lines = true, means do not include code lines started with #... +pub fn take_rustdoc_include_anchored_lines( + s: &str, + anchor: &str, + cutoff_commented_lines: bool, +) -> String { let mut output = String::with_capacity(s.len()); let mut within_anchored_section = false; @@ -105,13 +118,20 @@ pub fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str) -> String { within_anchored_section = true; } } else if !ANCHOR_END.is_match(l) { - output.push_str("# "); - output.push_str(l); - output.push('\n'); + if !cutoff_commented_lines { + // do not include 'dashed' lines (for epub format) + output.push_str("# "); + output.push_str(l); + output.push('\n'); + } } } output.pop(); + trace!( + "take_rustdoc_include_anchored_lines = {:?}", + output.to_string() + ); output } @@ -169,87 +189,87 @@ mod tests { fn take_rustdoc_include_lines_test() { let s = "Lorem\nipsum\ndolor\nsit\namet"; assert_eq!( - take_rustdoc_include_lines(s, 1..3), + take_rustdoc_include_lines(s, 1..3, false), "# Lorem\nipsum\ndolor\n# sit\n# amet" ); assert_eq!( - take_rustdoc_include_lines(s, 3..), + take_rustdoc_include_lines(s, 3.., false), "# Lorem\n# ipsum\n# dolor\nsit\namet" ); assert_eq!( - take_rustdoc_include_lines(s, ..3), + take_rustdoc_include_lines(s, ..3, false), "Lorem\nipsum\ndolor\n# sit\n# amet" ); - assert_eq!(take_rustdoc_include_lines(s, ..), s); + assert_eq!(take_rustdoc_include_lines(s, .., false), s); // corner cases assert_eq!( - take_rustdoc_include_lines(s, 4..3), + take_rustdoc_include_lines(s, 4..3, false), "# Lorem\n# ipsum\n# dolor\n# sit\n# amet" ); - assert_eq!(take_rustdoc_include_lines(s, ..100), s); + assert_eq!(take_rustdoc_include_lines(s, ..100, false), s); } #[test] fn take_rustdoc_include_anchored_lines_test() { let s = "Lorem\nipsum\ndolor\nsit\namet"; assert_eq!( - take_rustdoc_include_anchored_lines(s, "test"), + take_rustdoc_include_anchored_lines(s, "test", false), "# Lorem\n# ipsum\n# dolor\n# sit\n# amet" ); let s = "Lorem\nipsum\ndolor\nANCHOR_END: test\nsit\namet"; assert_eq!( - take_rustdoc_include_anchored_lines(s, "test"), + take_rustdoc_include_anchored_lines(s, "test", false), "# Lorem\n# ipsum\n# dolor\n# sit\n# amet" ); let s = "Lorem\nipsum\nANCHOR: test\ndolor\nsit\namet"; assert_eq!( - take_rustdoc_include_anchored_lines(s, "test"), + take_rustdoc_include_anchored_lines(s, "test", false), "# Lorem\n# ipsum\ndolor\nsit\namet" ); assert_eq!( - take_rustdoc_include_anchored_lines(s, "something"), + take_rustdoc_include_anchored_lines(s, "something", false), "# Lorem\n# ipsum\n# dolor\n# sit\n# amet" ); let s = "Lorem\nipsum\nANCHOR: test\ndolor\nsit\namet\nANCHOR_END: test\nlorem\nipsum"; assert_eq!( - take_rustdoc_include_anchored_lines(s, "test"), + take_rustdoc_include_anchored_lines(s, "test", false), "# Lorem\n# ipsum\ndolor\nsit\namet\n# lorem\n# ipsum" ); assert_eq!( - take_rustdoc_include_anchored_lines(s, "something"), + take_rustdoc_include_anchored_lines(s, "something", false), "# Lorem\n# ipsum\n# dolor\n# sit\n# amet\n# lorem\n# ipsum" ); let s = "Lorem\nANCHOR: test\nipsum\nANCHOR: test\ndolor\nsit\namet\nANCHOR_END: test\nlorem\nipsum"; assert_eq!( - take_rustdoc_include_anchored_lines(s, "test"), + take_rustdoc_include_anchored_lines(s, "test", false), "# Lorem\nipsum\ndolor\nsit\namet\n# lorem\n# ipsum" ); assert_eq!( - take_rustdoc_include_anchored_lines(s, "something"), + take_rustdoc_include_anchored_lines(s, "something", false), "# Lorem\n# ipsum\n# dolor\n# sit\n# amet\n# lorem\n# ipsum" ); let s = "Lorem\nANCHOR: test2\nipsum\nANCHOR: test\ndolor\nsit\namet\nANCHOR_END: test\nlorem\nANCHOR_END:test2\nipsum"; assert_eq!( - take_rustdoc_include_anchored_lines(s, "test2"), + take_rustdoc_include_anchored_lines(s, "test2", false), "# Lorem\nipsum\ndolor\nsit\namet\nlorem\n# ipsum" ); assert_eq!( - take_rustdoc_include_anchored_lines(s, "test"), + take_rustdoc_include_anchored_lines(s, "test", false), "# Lorem\n# ipsum\ndolor\nsit\namet\n# lorem\n# ipsum" ); assert_eq!( - take_rustdoc_include_anchored_lines(s, "something"), + take_rustdoc_include_anchored_lines(s, "something", false), "# Lorem\n# ipsum\n# dolor\n# sit\n# amet\n# lorem\n# ipsum" ); let s = "Lorem\nANCHOR: test\nipsum\nANCHOR_END: test\ndolor\nANCHOR: test\nsit\nANCHOR_END: test\namet"; assert_eq!( - take_rustdoc_include_anchored_lines(s, "test"), + take_rustdoc_include_anchored_lines(s, "test", false), "# Lorem\nipsum\n# dolor\nsit\n# amet" ); } diff --git a/tests/build_process.rs b/tests/build_process.rs index 10d0b4a9a8..994f3940b5 100644 --- a/tests/build_process.rs +++ b/tests/build_process.rs @@ -9,6 +9,7 @@ use mdbook::renderer::{RenderContext, Renderer}; use mdbook::MDBook; use std::sync::{Arc, Mutex}; +#[derive(Clone)] struct Spy(Arc>); #[derive(Debug, Default)] diff --git a/tests/init.rs b/tests/init.rs index e952ed1991..74ff4e0d3c 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -29,7 +29,7 @@ fn base_mdbook_init_should_create_default_content() { let contents = fs::read_to_string(temp.path().join("book.toml")).unwrap(); assert_eq!( contents, - "[book]\nauthors = []\nlanguage = \"en\"\nmultilingual = false\nsrc = \"src\"\n" + "[book]\nauthors = []\nlanguage = \"en\"\nmultilingual = false\nsrc = \"src\"\nversion = \"0.0.1\"\n" ); } @@ -94,7 +94,7 @@ fn run_mdbook_init_with_custom_book_and_src_locations() { let contents = fs::read_to_string(temp.path().join("book.toml")).unwrap(); assert_eq!( contents, - "[book]\nauthors = []\nlanguage = \"en\"\nmultilingual = false\nsrc = \"in\"\n\n[build]\nbuild-dir = \"out\"\ncreate-missing = true\nextra-watch-dirs = []\nuse-default-preprocessors = true\n" + "[book]\nauthors = []\nlanguage = \"en\"\nmultilingual = false\nsrc = \"in\"\nversion = \"0.0.1\"\n\n[build]\nbuild-dir = \"out\"\ncreate-missing = true\nextra-watch-dirs = []\nuse-default-preprocessors = true\n" ); } diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index beb83ebd48..e9ed5ced39 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -627,7 +627,7 @@ fn edit_url_has_default_src_dir_edit_url() { title = "implicit" [output.html] - edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}" + edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}" "#; write_file(temp.path(), "book.toml", book_toml.as_bytes()).unwrap();