Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Feature/links preprocessor #1

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
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
97559ed
added ability to clone preprocessors
blandger Nov 5, 2020
7a0a00b
added logging
blandger Nov 14, 2020
a1fb0be
added conditional execution
blandger Nov 16, 2020
b95603c
little info on run
blandger Nov 21, 2020
cce622b
added book version
blandger Nov 24, 2020
21a0c31
removed DEBUG, added book 'version' field, updated unit tests
blandger Nov 25, 2020
64ae516
added comments
blandger Nov 25, 2020
fe60746
After Merge remote-tracking branch 'upstream/master' # Conflicts: # …
blandger Apr 26, 2021
3cc02dc
add semver v0.11.0 for example
joshrotenberg Apr 26, 2021
e869e29
restructure guide configuration section
joshrotenberg May 24, 2021
80b8567
book: use non_exhaustive attribute for struct Book
xrmx May 30, 2021
08b253d
use book_config.src for edit path
joshrotenberg May 28, 2021
df3ab69
Revert "book: use non_exhaustive attribute for struct Book"
joshrotenberg Jun 8, 2021
79530e1
Update renderers.md
fritsstegmann Jul 4, 2021
d34483f
first pass at 2021 support
joshrotenberg Jul 4, 2021
ce996d4
add edition2021 as an option
joshrotenberg Jul 4, 2021
6610b3c
remove debugging
joshrotenberg Jul 5, 2021
4f5f750
add init flags
joshrotenberg Jun 1, 2021
846f120
drop short flags
joshrotenberg Jul 4, 2021
9d53d20
ignore now takes a value
joshrotenberg Jul 4, 2021
8a20034
Merge remote-tracking branch 'upstream/master'
blandger Dec 23, 2022
3813e40
added use macros
blandger Dec 25, 2022
d4162d3
synched with upstream
blandger Dec 25, 2022
2b4a55f
import clean up
blandger Apr 16, 2023
2052b46
sparse registry
blandger Apr 16, 2023
9c7107b
version was lost, added back
blandger Apr 16, 2023
1b92cc6
restored functionality
blandger Apr 17, 2023
a1ae669
RESTORED ! one chapter processing functionality
blandger Apr 17, 2023
8a7b3f8
minor log
blandger May 25, 2023
d731e40
sparse is not needed anymore
blandger Jun 20, 2023
e944a66
rust fmt fixes
blandger Jun 21, 2023
167cb2c
rebased 0.4.40
blandger Aug 18, 2024
9b37fb5
rebased to 0.4.43
blandger Jan 5, 2025
4431628
rustfmt fixes
blandger Jan 5, 2025
bb5b98f
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 @@ -287,6 +297,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 @@ -317,3 +374,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 @@ -426,6 +426,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 @@ -865,6 +870,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 @@ -414,6 +414,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 @@ -426,6 +428,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 @@ -792,6 +795,7 @@ mod tests {
multilingual = true
src = "source"
language = "ja"
version = "0.0.1"

[build]
build-dir = "outputs"
Expand Down Expand Up @@ -832,6 +836,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
Loading