-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Configurable preprocessor #658
Conversation
@Michael-F-Bryan To me this looks good. It allows a user fine control on which preprocessors should run when, without to much of configuration. 👍 |
This LGTM as well. I'm looking into the netbsd failure. We're probably going to have to disable that target for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Will plugin preprocessors also come in with this PR?
src/preprocess/mod.rs
Outdated
/// particular renderer. | ||
/// | ||
/// By default, always returns `true`. | ||
fn supports_renderer(&self, _renderer: &str) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be this function is never called? (I am using the webview to see all changed files at once, and this one doesn’t show up anywhere else)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, maybe it’s still a WIP, and it’s more about comments on the general direction :). Never mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this PR is still a work in progress. Eventually I want to extract the logic out into a should_run()
function which will check the config if the user explicitly overrides what preprocessors are run, then fall back to asking a preprocessor directly whether it supports a specific renderer.
I was thinking that can be a second PR. This one mainly deals with the issue of making sure certain preprocessors only get run for the renderers they support. That's the big thing blocking #626 at the moment. |
8b53d41
to
e84136c
Compare
I got a full time job and ran out of time :( That said, this PR is quite small so I'll see what I can do tonight to un-bitrot it. |
e84136c
to
4d7027f
Compare
@rbuckland I still need to update the user guide to reflect the changes, but in a nutshell this PR will:
This should hopefully pave the way for creating custom preprocessors, using the @mattico or @rbuckland would one of you be able to review this and let me know what you think? All the tests pass and I think it behaves as I would like, but I literally put it together while lying in bed and it'll need a second set of eyes before it's safe to merge. |
That’s excellent @Michael-F-Bryan I will review over today. |
Hi @Michael-F-Bryan, I have some good news for you. I looked over the code, ✅, this will unblock me to add some of the features I and others are calling out for, Regarding if it "breaks" anything (ignoring the breaking change you called out on config) I took the liberty to script up a force check of mdbook (2x versions) against multiple "other" book.toml repos. And the result is that
All generated identically with the current "master" version and this "smart-preprocessor" version. I created a PR on your branch that adds those scripts (as they are some what re-usable). |
I am moving these test scripts over to a separate branch https://github.com/rbuckland/mdBook/tree/feature/other-books-test-scripts |
@mattico and @rbuckland, I think this PR is pretty much good to go. Can you see any points we forgot to address or fix up? |
I think it looks good @Michael-F-Bryan. |
* The preprocessor trait now returns a modified book instead of editing in place * A preprocessor is told which render it's running for * Made sure preprocessors get their renderer's name * Users can now manually specify whether a preprocessor should run for a renderer * You can normally use default preprocessors by default * Got my logic around the wrong way * Fixed the `build.use-default-preprocessors` flag
This adds the ability to configure a Preprocessor and specify which renderers it gets run for.
It effectively changes the build step to be something like:
Where the
should_run()
function inspects thebook.toml
to first ensure we're allowed to run this preprocessor with a specific renderer, falling back to a newPreprocessor::supports_renderer()
method if the user doesn't say anything. This setup means the user always has the final say, via theirbook.toml
.We'll need to update the
book.toml
format to have abuild.use-default-preprocessors
flag now preprocessors have their own[preprocessor.*]
set of tables.I'll update the
Configuration
section in the user guide, but for now this is how I imagine the relevant sections inbook.toml
will look.cc: #626