Skip to content

Commit

Permalink
rebased 0.4.40
Browse files Browse the repository at this point in the history
  • Loading branch information
blandger committed Aug 18, 2024
1 parent 56051be commit 52d999d
Show file tree
Hide file tree
Showing 11 changed files with 7 additions and 107 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ assert_cmd = "2.0.11"
predicates = "3.0.3"
select = "0.6.0"
semver = "1.0.17"
semver = "0.11.0"
pretty_assertions = "1.3.0"
walkdir = "2.3.3"

Expand Down
4 changes: 0 additions & 4 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,6 @@ impl MDBook {
RustEdition::E2024 => {
cmd.args(["--edition", "2024", "-Zunstable-options"]);
}
RustEdition::E2021 => {
cmd.args(&["--edition", "2021"])
.args(&["-Z", "unstable-options"]);
}
}
}

Expand Down
17 changes: 1 addition & 16 deletions src/cmd/init.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::get_book_dir;
use clap::{arg, Arg, ArgMatches, Command as ClapCommand};
use clap::{arg, ArgMatches, Command as ClapCommand};
use mdbook::config;
use mdbook::errors::Result;
use mdbook::MDBook;
Expand All @@ -25,21 +25,6 @@ pub fn make_subcommand() -> ClapCommand {
arg!(--ignore <ignore> "Creates a VCS ignore file (i.e. .gitignore)")
.value_parser(["none", "git"]),
)
.arg(
Arg::with_name("title")
.long("title")
.takes_value(true)
.help("Sets the book title")
.required(false),
)
.arg(
Arg::with_name("ignore")
.long("ignore")
.takes_value(true)
.possible_values(&["none", "git"])
.help("Creates a VCS ignore file (i.e. .gitignore)")
.required(false),
)
}

// Init command implementation
Expand Down
20 changes: 0 additions & 20 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,26 +969,6 @@ mod tests {
assert_eq!(got.rust, rust_should_be);
}

#[test]
fn edition_2021() {
let src = r#"
[book]
title = "mdBook Documentation"
description = "Create book from markdown files. Like Gitbook but implemented in Rust"
authors = ["Mathieu David"]
src = "./source"
[rust]
edition = "2021"
"#;

let rust_should_be = RustConfig {
edition: Some(RustEdition::E2021),
};

let got = Config::from_str(src).unwrap();
assert_eq!(got.rust, rust_should_be);
}

#[test]
fn load_arbitrary_output_type() {
#[derive(Debug, Deserialize, PartialEq)]
Expand Down
1 change: 0 additions & 1 deletion src/preprocess/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::book::{Book, BookItem};
use crate::errors::*;
use log::warn;
use once_cell::sync::Lazy;
use std::fmt::{Formatter, Debug};

/// A preprocessor for converting file name `README.md` to `index.md` since
/// `README.md` is the de facto index file in markdown-based documentation.
Expand Down
24 changes: 3 additions & 21 deletions src/preprocess/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ use std::path::{Path, PathBuf};

use super::{Preprocessor, PreprocessorContext};
use crate::book::{Book, BookItem, Chapter};
use std::{
fmt::{Debug, Formatter},
};
use log::{error, trace, warn};
use std::fmt::Debug;
use log::{debug, error, trace, warn};
use once_cell::sync::Lazy;
use ammonia::url::form_urlencoded::Target;

Expand Down Expand Up @@ -530,23 +528,7 @@ mod tests {
end
);
}

#[test]
fn test_set_chapter_title() {
let start = r"{{#title My Title}}
# My Chapter
";
let end = r"
# My Chapter
";
let mut chapter_title = "test_set_chapter_title".to_owned();
assert_eq!(
replace_all(start, "", "", 0, &mut chapter_title, false),
end
);
assert_eq!(chapter_title, "My Title");
}


#[test]
fn test_find_links_no_link() {
let s = "Some random text without link...";
Expand Down
26 changes: 1 addition & 25 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ fn hide_lines_with_prefix(content: &str, prefix: &str) -> String {
continue;
}
result += line;
result += newline;
result += "\n";
}
result
}
Expand Down Expand Up @@ -1202,30 +1202,6 @@ mod tests {
}
}
#[test]
fn add_playground_edition2021() {
let inputs = [
("<code class=\"language-rust\">x()</code>",
"<pre class=\"playground\"><code class=\"language-rust edition2021\"><span class=\"boring\">#![allow(unused)]\n</span><span class=\"boring\">fn main() {\n</span>x()\n<span class=\"boring\">}</span></code></pre>"),
("<code class=\"language-rust\">fn main() {}</code>",
"<pre class=\"playground\"><code class=\"language-rust edition2021\">fn main() {}</code></pre>"),
("<code class=\"language-rust edition2015\">fn main() {}</code>",
"<pre class=\"playground\"><code class=\"language-rust edition2015\">fn main() {}</code></pre>"),
("<code class=\"language-rust edition2018\">fn main() {}</code>",
"<pre class=\"playground\"><code class=\"language-rust edition2018\">fn main() {}</code></pre>"),
];
for (src, should_be) in &inputs {
let got = add_playground_pre(
src,
&Playground {
editable: true,
..Playground::default()
},
Some(RustEdition::E2021),
);
assert_eq!(&*got, *should_be);
}
}
#[test]
fn add_playground_edition2021() {
let inputs = [
("<code class=\"language-rust\">x()</code>",
Expand Down
1 change: 0 additions & 1 deletion src/renderer/html_handlebars/helpers/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use handlebars::{
Context, Handlebars, Helper, Output, RenderContext, RenderError, RenderErrorReason,
};
use log::trace;
use log::trace;

pub fn theme_option(
h: &Helper<'_>,
Expand Down
2 changes: 0 additions & 2 deletions src/utils/fs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::errors::*;
use log::{debug, trace};
use log::{debug, trace};
use log::{debug, trace};
use std::fs::{self, File};
use std::io::Write;
use std::path::{Component, Path, PathBuf};
Expand Down
1 change: 1 addition & 0 deletions src/utils/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use once_cell::sync::Lazy;
use regex::Regex;
use std::ops::Bound::{Excluded, Included, Unbounded};
use std::ops::RangeBounds;
use log::trace;

/// Take a range of lines from a string.
pub fn take_lines<R: RangeBounds<usize>>(s: &str, range: R) -> String {
Expand Down
17 changes: 1 addition & 16 deletions tests/rendered_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,21 +478,6 @@ fn first_chapter_is_copied_as_index_even_if_not_first_elem() {
pretty_assertions::assert_eq!(chapter, index);
}

#[test]
fn first_chapter_is_copied_as_index_even_if_not_first_elem() {
let temp = DummyBook::new().build().unwrap();
let mut cfg = Config::default();
cfg.set("book.src", "index_html_test")
.expect("Couldn't set config.book.src to \"index_html_test\"");
let md = MDBook::load_with_config(temp.path(), cfg).unwrap();
md.build().unwrap();

let root = temp.path().join("book");
let chapter = fs::read_to_string(root.join("chapter_1.html")).expect("read chapter 1");
let index = fs::read_to_string(root.join("index.html")).expect("read index");
pretty_assertions::assert_eq!(chapter, index);
}

#[test]
fn theme_dir_overrides_work_correctly() {
let book_dir = dummy_book::new_copy_of_example_book().unwrap();
Expand Down Expand Up @@ -623,7 +608,7 @@ fn edit_url_has_configured_src_dir_edit_url() {
src = "src2"
[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();
Expand Down

0 comments on commit 52d999d

Please sign in to comment.