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 option to remove indentation of included file snippets #1601

Open
holly-hacker opened this issue Jul 10, 2021 · 1 comment
Open

Add option to remove indentation of included file snippets #1601

holly-hacker opened this issue Jul 10, 2021 · 1 comment
Labels
A-link-preprocessor Area: Link preprocessor, #{{include}}, etc.

Comments

@holly-hacker
Copy link

I am using mdBook to write documentation about a code framework and include code snippets from an example project with the {{#include file.rs:component}} syntax. Because the code is written in C#, there is typically a lot more indented than with rust code meaning that when I include a single method, it will have at least 2 levels of indentation. Obviously it looks rather silly when all code in your documentation has 2 extra tabs :)

I want to propose adding an extension to the #include syntax to remove this extra indentation. I'm not sure yet how exactly this would look, but one way is to add a :-no-indent suffix to the filename that indicates that extra indentation should be removed (eg. {{@include file.rs:-no-indent}} or {{@include file.rs:component:-no-indent}}). Then, the preprocessor would look at every non-empty or non-whitespace line to find the minimum amount of whitespace, and remove that from all included lines.

Before (note that the 4th line is completely empty):

		public void MyMethod()
		{
			int x = 1;

			Console.WriteLine(x);
		}

After:

public void MyMethod()
{
	int x = 1;

	Console.WriteLine(x);
}
@ehuss ehuss added A-Links Area: Issues with links A-link-preprocessor Area: Link preprocessor, #{{include}}, etc. and removed A-Links Area: Issues with links labels Sep 8, 2021
@ISSOtm
Copy link
Contributor

ISSOtm commented Jun 18, 2022

This sounds like it might be more useful to add to code blocks are than to this preproc?

daviddrysdale added a commit to daviddrysdale/mdBook that referenced this issue Mar 1, 2024
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).

Possibly helpful/relevant to:
- rust-lang#1564: #include with indented
- rust-lang#1601: option to remove indentation of included file snippets
daviddrysdale added a commit to daviddrysdale/mdBook that referenced this issue Mar 1, 2024
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).

Possibly helpful/relevant to:
- rust-lang#1564: #include with indented
- rust-lang#1601: option to remove indentation of included file snippets
daviddrysdale added a commit to daviddrysdale/mdBook that referenced this issue Mar 2, 2024
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).

Possibly helpful/relevant to:
- rust-lang#1564: #include with indented
- rust-lang#1601: option to remove indentation of included file snippets
daviddrysdale added a commit to daviddrysdale/mdBook that referenced this issue Mar 2, 2024
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).

Possibly helpful/relevant to:
- rust-lang#1564: #include with indented
- rust-lang#1601: option to remove indentation of included file snippets
daviddrysdale added a commit to daviddrysdale/mdBook that referenced this issue Mar 2, 2024
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).

Possibly helpful/relevant to:
- rust-lang#1564: #include with indented
- rust-lang#1601: option to remove indentation of included file snippets
daviddrysdale added a commit to daviddrysdale/mdBook that referenced this issue Mar 2, 2024
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).

Possibly helpful/relevant to:
- rust-lang#1564: #include with indented
- rust-lang#1601: option to remove indentation of included file snippets
daviddrysdale added a commit to daviddrysdale/mdBook that referenced this issue Mar 2, 2024
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).

Possibly helpful/relevant for:
- rust-lang#1564: #include with indented
- rust-lang#1601: option to remove indentation of included file snippets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-link-preprocessor Area: Link preprocessor, #{{include}}, etc.
Projects
None yet
Development

No branches or pull requests

3 participants