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

Admonish doesn't work with mdbook test #108

Closed
stevecheckoway opened this issue Jul 20, 2023 · 5 comments · Fixed by #109
Closed

Admonish doesn't work with mdbook test #108

stevecheckoway opened this issue Jul 20, 2023 · 5 comments · Fixed by #109

Comments

@stevecheckoway
Copy link

If I use an admonish example (or other box) containing a code example, mdbook test will not test that example.
Here's an example of an example that doesn't get tested.

``````admonish example
Here's an example
```rust
let x = 10;
x = 20;
```
``````

If I take it out of an admonish example fenced code block, the code is tested (and fails as expected).

Is there a way to make this work?

@tommilligan
Copy link
Owner

tommilligan commented Jul 20, 2023

Hmm, interesting limitation. My guess is that mdbook test skips any code blocks that are not considered rust source code (i.e. have the info string rust, or have an empty info string). My intuition is that you'd have to change the behaviour of mdbook to look inside code blocks for other code blocks to test (which I think is bad, and probably won't be accepted upstream).

As mdbook-admonish respects import statements, I think you could work around this by putting your code snippets in another file, importing it inside admonish, and then importing it again not inside an admonish. The plain import should get picked up and tested.

Note that you may need to first tweak your book.toml settings to make includes expand in the right order.

So something like:

# My nice book page

Code on this page is not tested

````admonish
```rust
{{#include some_rust_code.rs}}
```
````
# My secret test page

Code on this page is tested

```rust
{{#include some_rust_code.rs}}
```
// some_rust_code.rs
let x = 10;
x = 20;

Something like this works for me locally, though I agree it's a bit of a pain.

@stevecheckoway
Copy link
Author

I just had a thought about this. It looks like mdbook test will run preprocessors, but just those that support the "test" renderer, I think anyway.

I have to run and haven't had a chance to try this, but I thought I'd mention it since it might be as simple as having mdbook-admonish support the test renderer. I'll try to test it later today.

@tommilligan
Copy link
Owner

Ah interesting. So I think you're right, I'd forgotten this system where we know the type of rendering that's being done.

If we're in test mode, we could simply strip out all admonish-specific syntax, leaving the bare internals behind. Then, if they're code blocks, they should be picked up afterwards.

I'll have a look at that now

@tommilligan
Copy link
Owner

This appears to support your use case - take a look and let me know any thoughts: #109

@tommilligan
Copy link
Owner

Released in v1.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants