Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3be52a4
added ability to clone preprocessors
blandger Nov 5, 2020
bb0c74b
added logging
blandger Nov 14, 2020
edfc250
added conditional execution
blandger Nov 16, 2020
bb057d9
little info on run
blandger Nov 21, 2020
869c542
added book version
blandger Nov 24, 2020
d729416
removed DEBUG, added book 'version' field, updated unit tests
blandger Nov 25, 2020
7f041fe
added comments
blandger Nov 25, 2020
49b8892
After Merge remote-tracking branch 'upstream/master' # Conflicts: # …
blandger Apr 26, 2021
b87f538
add semver v0.11.0 for example
joshrotenberg Apr 26, 2021
9b899af
restructure guide configuration section
joshrotenberg May 24, 2021
fa955d3
book: use non_exhaustive attribute for struct Book
xrmx May 30, 2021
ed4c7a8
use book_config.src for edit path
joshrotenberg May 28, 2021
4d78aea
Revert "book: use non_exhaustive attribute for struct Book"
joshrotenberg Jun 8, 2021
b632b9c
Update renderers.md
fritsstegmann Jul 4, 2021
b78b8cd
first pass at 2021 support
joshrotenberg Jul 4, 2021
2a4e2f3
add edition2021 as an option
joshrotenberg Jul 4, 2021
38e80da
remove debugging
joshrotenberg Jul 5, 2021
fea7b53
add init flags
joshrotenberg Jun 1, 2021
6fda6e3
drop short flags
joshrotenberg Jul 4, 2021
20bc4c1
ignore now takes a value
joshrotenberg Jul 4, 2021
8328912
Merge remote-tracking branch 'upstream/master'
blandger Dec 23, 2022
fe4013e
added use macros
blandger Dec 25, 2022
6591806
synched with upstream
blandger Dec 25, 2022
1c0a921
import clean up
blandger Apr 16, 2023
0fe2bda
sparse registry
blandger Apr 16, 2023
5ddded4
version was lost, added back
blandger Apr 16, 2023
9b9456a
restored functionality
blandger Apr 17, 2023
4ae3fb7
RESTORED ! one chapter processing functionality
blandger Apr 17, 2023
8c1117e
minor log
blandger May 25, 2023
09eae9d
sparse is not needed anymore
blandger Jun 20, 2023
1fcc6de
rust fmt fixes
blandger Jun 21, 2023
74f9e5d
rebased 0.4.40
blandger Aug 18, 2024
d0e78fe
rebased to 0.4.43
blandger Jan 5, 2025
c7e914b
rustfmt fixes
blandger Jan 5, 2025
e4108cc
compile fix
blandger Jan 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/nop-preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ mod nop_lib {
use super::*;

/// A no-op preprocessor.
#[derive(Clone)]
pub struct Nop;

impl Nop {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn main() {
}
}

#[derive(Clone)]
struct RemoveEmphasis;

impl Preprocessor for RemoveEmphasis {
Expand Down
2 changes: 1 addition & 1 deletion guide/src/format/configuration/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions guide/src/format/configuration/preprocessors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
```
Expand Down
74 changes: 74 additions & 0 deletions guide/src/format/configuration/renderers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -157,6 +161,12 @@ The following configuration options are available:
`https://bitbucket.org/<owner>/<repo>/src/<branch>/{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`.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@ impl MDBook {
.unwrap_or_default()
.theme_dir(&self.root)
}

/// Clone registered boxed preprocessors Vec
pub fn clone_preprocessors(&self) -> Vec<Box<dyn Preprocessor>> {
self.preprocessors.clone()
}
}

/// Look at the `Config` and try to figure out what renderers to use.
Expand Down Expand Up @@ -867,6 +872,7 @@ mod tests {
assert!(should_run);
}

#[derive(Default, Clone)]
struct BoolPreprocessor(bool);
impl Preprocessor for BoolPreprocessor {
fn name(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/test.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextDirection>,
/// The book version.
pub version: Option<String>,
}

impl Default for BookConfig {
Expand All @@ -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")),
}
}
}
Expand Down Expand Up @@ -823,6 +826,7 @@ mod tests {
multilingual = true
src = "source"
language = "ja"
version = "0.0.1"

[build]
build-dir = "outputs"
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion src/preprocess/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading