mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Add {{#shiftinclude}} command

Open daviddrysdale opened this issue 1 year ago • 4 comments

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 issues[^1] that this might help with :

  • #1430
    • Covered by {{#shiftinclude auto:file.rs}} here.
  • #1564
    • Covered by {{#shiftinclude +4:myfn.rs}} here.
  • #1601
    • Covered by {{#shiftinclude auto:file.rs}} here.
  • #1626
    • Helped by {{#shiftinclude +4:../exercises/chapter6/test/no-peeking/Solutions.purs:eqNonEmpty}} (but would need to be left-aligned).

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

  • #1565
  • #1718
  • #1856
    • This PR looks to have similar functionality to the auto variant here (and is also careful not to affect existing behaviour).

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

daviddrysdale avatar Mar 02 '24 16:03 daviddrysdale

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.

daviddrysdale avatar Mar 30 '24 10:03 daviddrysdale