mdbook-shiftinclude

Crates.iomdbook-shiftinclude
lib.rsmdbook-shiftinclude
version0.1.0
sourcesrc
created_at2024-03-30 10:04:01.874484
updated_at2024-03-30 10:04:01.874484
descriptionmdbook preprocessor for file inclusion with shift
homepage
repositoryhttps://github.com/daviddrysdale/mdbook-shiftinclude
max_upload_size
id1190988
size106,258
David Drysdale (daviddrysdale)

documentation

README

mdbook-shiftinclude

A preprocessor for mdbook for including portions of files, but with the contents of the file shifted.

The {{#shiftinclude }} command extends the syntax of the normal {{#include }} command to include a shift indicator. This is followed by a colon, and then the normal include syntax follows.

  • A number, indicating the amount to shift.
    • A positive number shifts right by prepending that number of spaces to each line.
    • A negative number shifts left by removing that number of characters from the start of each line (regardless of whether they are spaces or not!).
  • auto, which indicates that any block of whitespace that is common to all (non-empty) lines in the included text will be removed.

So for an input file somefile.txt:

  Indent
     More Indent
  Back

The following outputs are possible:

  • {{#shiftinclude auto:somefile.txt} gives
    Indent
       More Indent
    Back
    
  • {{#shiftinclude 2:somefile.txt} gives
        Indent
           More Indent
        Back
    
  • {{#shiftinclude -2:somefile.txt} gives
    Indent
       More Indent
    Back
    
  • {{#shiftinclude -4:somefile.txt} gives
    dent
     More Indent
    ck
    

Installation

To use, install the tool

cargo install mdbook-shiftinclude

and add it as a preprocessor in book.toml:

[preprocessor.shiftinclude]
Commit count: 6

cargo fmt