Skip to content

Add option to remove indentation of included file snippets #1601

Open
@holly-hacker

Description

@holly-hacker

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-link-preprocessorArea: Link preprocessor, #{{include}}, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions