Description
First, this ticket isn't a bug, it's more like a feature request.
{{#include ...}}
currently does not consider indentation when replaced.
For example, replace some code of a control flow, struct, enum, and implementation from another file, and dealing with a code block that is indented with bullets or sequences, the second and subsequent lines are not indented.
As a result, the HTML layout and code indentation may be corrupted.
Example code
# sample.md
- Example without including files.
```rust
struct MyStruct;
impl MyStruct {
pub fn myfn() -> () {
println!("MyStruct#myfn()");
}
}
pub fn main() -> () {
println!("main()");
}
```
- Example using including files.
```rust
struct MyStruct;
impl MyStruct {
{{#include myfn.rs}}
}
{{#include main.rs}}
```
// myfn.rs
pub fn myfn() -> () {
println!("MyStruct#myfn()");
}
// main.rs
pub fn main() -> () {
println!("main()");
}
Personally, I expected that both cases with and without {{#include}}
would be output with the same layout.
However, the inclusion of myfn.rs
and main.rs
does not indent the second and subsequent lines, so the results are different as shown below.
Output HTML
-
Without including files.
<p>Example without including files.</p> <pre><pre class="playground"><code class="language-rust">struct MyStruct; impl MyStruct { pub fn myfn() -> () { println!("MyStruct#myfn()"); } } pub fn main() -> () { println!("main()"); } </code></pre></pre>
-
Using including files.
<p>Example using including files.</p> <pre><pre class="playground"><code class="language-rust"> <span class="boring">#![allow(unused)] </span><span class="boring">fn main() { </span>struct MyStruct; impl MyStruct { pub fn myfn() -> () { println!("MyStruct#myfn()"); <span class="boring">} </span></code></pre></pre> </li> </ul> <p>} }</p> <p>pub fn main() -> () { println!("main()"); }</p> <pre><code></code></pre>
I will submit a Draft PR that allows to output the same results.