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 {{#shiftinclude}} command #2333

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

daviddrysdale
Copy link

Allows included code to be shifted left or right by a specified amount, or to be automatically left-shifted so that common leading whitespace is stripped.

Uses a new command name #shiftinclude to avoid changing the behaviour of any existing books.

There are few open issues1 that this might help with :

There are also a few open PRs that this might overtake/replace/combine-with:

Footnotes

  1. I confess that I implemented this without looking at the current open issues/pull requests.

Syntax is the same as {{#include}} except with a shift value and colon
before the remaining arguments, e.g.

  {{#include -2:somefile.rs:myanchor}}

A positive value for the shift prepends spaces to each line.

A negative value for the shift removes chars from the beginning of each
line (including non-whitespace chars, although this will emit an error
log).
@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Mar 2, 2024
As well as allowing explicitly-specified shift amounts, also
support an "auto" option that strips common leftmost whitespace
from an inclusion.
daviddrysdale added a commit to daviddrysdale/mdbook-shiftinclude that referenced this pull request Mar 30, 2024
Taken from suggested pull request for upstream:
rust-lang/mdBook#2333
daviddrysdale added a commit to daviddrysdale/mdbook-shiftinclude that referenced this pull request Mar 30, 2024
Taken from suggested pull request for upstream:
rust-lang/mdBook#2333
daviddrysdale added a commit to daviddrysdale/mdbook-shiftinclude that referenced this pull request Mar 30, 2024
Taken from suggested pull request for upstream:
rust-lang/mdBook#2333
@daviddrysdale
Copy link
Author

Given that this looks unlikely to be included in the main mdBook code, I've pulled the functionality out into a separate mdbook-shiftinclude preprocessor.

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.

None yet

2 participants