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
17.61k stars 1.61k forks source link

Let `mdbook build` select renderer and preprocessors #1978

Open mgeisler opened 1 year ago

mgeisler commented 1 year ago

I'm adding support for translations to https://github.com/google/comprehensive-rust/ — via the code I posted in #1864. My plan is to do this via a renderer and a preprocessor:

Hooking into mdbook like this seems nice: I don't need to know about where the Markdown files are on disk and I can reuse things such as BookItem.

However, I don't need the renderer and the preprocessor most of the time: I only need them when publishing a new version. It would therefore be nice if mdbook build would have new command line options which lets me enable/disable the renderer and preprocessor.

Does that sound like a reasonable idea? I think mdbook serve should have the same options.

My workaround right now is to modify the book.toml file to enable the renderer and preprocessor when needed.

mgeisler commented 1 year ago

I found a better work-around: use the MDBOOK_ environment variable to override the renderer and preprocessor as needed.

With that, I think this issue can be closed.

mgeisler commented 4 months ago

We had a discussion in https://github.com/google/comprehensive-rust/pull/1998 about a similar topic: how can we include configuration for a renderer (mdbook-pandoc in this case) without requiring that everybody installs the dependencies for the renderer?

One solution would be to let mdbook build and serve take a list of renderer to use. That would be a subset of the renderers configured in book.toml.

Another solution just occurred to me: we could extract the configuration that isn't used all the time to a separate file. When we want to use it, we do something like

MDBOOK_OUTPUT=$(cat pandoc.json) mdbook build