rust-lang / mdBook

Create book from markdown files. Like Gitbook but implemented in Rust
https://rust-lang.github.io/mdBook/
Mozilla Public License 2.0
18.11k stars 1.63k forks source link

build > preprocess ? i think it not working, and preprocessor help me #835

Closed chinanf-boy closed 5 years ago

chinanf-boy commented 5 years ago

1. mdbook doc site say

That preprocess can handle the preprocess

[build]
build-dir = "build"
create-missing = false
use-default-preprocessors = false # no use default pre, then
preprocess = ["links"] #  preprocess was not working 

But,preprocess = ["links"] no working

2. src/config.rs about BuildConfig even without field of preprocess ->ref

Am i right, i a Rookie of Rust

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case")]
pub struct BuildConfig {
    /// Where to put built artefacts relative to the book's root directory.
    pub build_dir: PathBuf,
    /// Should non-existent markdown files specified in `SETTINGS.md` be created
    /// if they don't exist?
    pub create_missing: bool,
    /// Should the default preprocessors always be used when they are
    /// compatible with the renderer?
    pub use_default_preprocessors: bool,
}

3. Solve

With [preprocessor.***]

[build]
build-dir = "build"
create-missing = false
use-default-preprocessors = false

[preprocessor.links] # 🌟 ok, it working

I found the key:preprocessor in src/book/mod.rs :: determine_preprocessors

fn determine_preprocessors(config: &Config) -> Result<Vec<Box<Preprocessor>>> {
--
  | let mut preprocessors = Vec::new();
  |  
  | if config.build.use_default_preprocessors {
  | preprocessors.extend(default_preprocessors());
  | }
  |  
  | if let Some(preprocessor_table) =
❤️| config.get("preprocessor").and_then(\|v\| v.as_table())
  | {
  | for key in preprocessor_table.keys() {
  | match key.as_ref() {
  | "links" => {
  | preprocessors.push(Box::new(LinkPreprocessor::new()))
  | }
  | "index" => {
  | preprocessors.push(Box::new(IndexPreprocessor::new()))
  | }
  | name => preprocessors.push(interpret_custom_preprocessor(
  | name,
  | &preprocessor_table[name],
  | )),
  | }
  | }
  | }
  |  
  | Ok(preprocessors)
  | }

Is that Docs wrong ?

Dylan-DPC-zz commented 5 years ago

@chinanf-boy are you still facing this issue?

chinanf-boy commented 5 years ago

@Dylan-DPC I try, still not working

1. cargo install mdbook --force update to v0.2.3

2. change book.toml

#...
[build]
build-dir = "docs"
create-missing = true
# use-default-preprocessors = false
preprocess = [] # fit the docs
# ...

docs:build options

server mdbook serve --open

still render the code {{# playpen}} and {{# include}} and README.md => index.md changed

No, not Working.

Other try preprocess = ["index"] as same as above

Is it the Fix of this in Dev(or master) Branch ? Shall i build mdBook crate on the Source Code.

Will be fix in the Next release ?