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

Add clear_renderers / clear_preprocessors #2542

Closed
wants to merge 1 commit into from

Conversation

dalance
Copy link
Contributor

@dalance dalance commented Feb 1, 2025

Now Renderer and Preprocessor can be added by with_renderer and with_preprocessor.
But there is no way to disable the existing renderers and preprocessors.
So this PR add clear_renderers and clear_preprocessors.
This addition enables the customization of renderer and preprocessor without modifying the original book.toml.

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Feb 1, 2025
@ehuss
Copy link
Contributor

ehuss commented Feb 17, 2025

Can you say more about why you can't modify the Config?

@dalance
Copy link
Contributor Author

dalance commented Feb 17, 2025

@ehuss

I want to use this API for Rust documents translation project: https://rust-lang-translations.org .

In most cases, the maintainers of the original version are negative to modify their repository for translation. Keeping forks for translation takes a lot of time because these documents are updated frequently.

So I need the way to customize renderer/preprocesser without modifing the original TOML.

@ehuss
Copy link
Contributor

ehuss commented Feb 18, 2025

If you are using the API, you should be able to load the config with Config::from_disk. Then modify the config, for example:

    if let Some(renderers) = config.get_mut("output").and_then(|o| o.as_table_mut()) {
        renderers.clear();
    }

and then use MdBook::load_with_config with whatever customizations you want. Does that work for you?

@dalance
Copy link
Contributor Author

dalance commented Feb 18, 2025

Thank you for your suggestion.
I missed load_with_config.

@dalance dalance closed this Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: waiting on a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants