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 include by anchor in preprocessor (partial include) #851

Merged
merged 2 commits into from
Jul 15, 2019

Conversation

CBenoit
Copy link
Contributor

@CBenoit CBenoit commented Dec 12, 2018

For issue #811.
I apologize for the late pull request.

I'm not super happy with
https://github.com/rust-lang-nursery/mdBook/pull/851/files#diff-d6ae283361f866777987f4630e148843R138
and
https://github.com/rust-lang-nursery/mdBook/pull/851/files#diff-182fe74cafd75eb44defddf4511f3591R70

Please, tell me what you think about the anchored syntax. I'll update the user guide after.

In current implementation, first anchor must match regex "ANCHOR:\s*[\w\d_-]+" and similarly the ending anchor must match "ANCHOR_END:\s*[\w\d_-]+". In included file:

/* ANCHOR: all */

// ANCHOR: component
struct Paddle {
    hello: f32,
}
// ANCHOR_END: component

////////// ANCHOR: system
impl System for MySystem { ... }
////////// ANCHOR_END: system

/* ANCHOR_END: all */

Then in the book:

```rust,no_run,noplaypen
{{#include file.rs:component}}
`` `

```rust,no_run,noplaypen
{{#include file.rs:system}}
`` `

```rust,no_run,noplaypen
{{#include file.rs:all}}
`` `

Lines containing anchor patterns inside the included anchor are ignored, as such the result is:

struct Paddle {
    hello: f32,
}
impl System for MySystem { ... }
struct Paddle {
    hello: f32,
}

impl System for MySystem { ... }

@CBenoit CBenoit changed the title Add include by anchor in preprocessor (partial include of code snippets) Add include by anchor in preprocessor (partial include) Dec 13, 2018
@nikomatsakis
Copy link

This would be so nice to have!

@CBenoit
Copy link
Contributor Author

CBenoit commented Jun 25, 2019

I would be happy to finish the work if I can get more feedback 👍

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks fine to me. Just needs a rebase and some docs.

@Dylan-DPC Do you have any thoughts on this?

src/utils/string.rs Outdated Show resolved Hide resolved
@nikomatsakis
Copy link

I'm very excited, I'd love to see this land. FWIW, I reviewed the code briefly and thought it looked good.

@ehuss
Copy link
Contributor

ehuss commented Jul 14, 2019

@CBenoit Do you think you'll be able to rebase this and add some docs? If not, that's ok, I can take it over if you don't have the time.

@CBenoit
Copy link
Contributor Author

CBenoit commented Jul 15, 2019

@ehuss I'm currently working on it! If everything rebase nicely it'll be finished soon.

@CBenoit
Copy link
Contributor Author

CBenoit commented Jul 15, 2019

Okay! Everything should be fine now 👍

@ehuss
Copy link
Contributor

ehuss commented Jul 15, 2019

Great, thanks!

@ehuss ehuss merged commit e7c3d02 into rust-lang:master Jul 15, 2019
Ruin0x11 pushed a commit to Ruin0x11/mdBook that referenced this pull request Aug 30, 2020
Add include by anchor in preprocessor (partial include)
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 this pull request may close these issues.

3 participants