Keep indent when using include in code block

This commit is contained in:
rchaser53 2022-01-02 19:34:55 +09:00
parent 68a5c09fdf
commit e22886a471
4 changed files with 754 additions and 352 deletions

View File

@ -89,19 +89,26 @@ where
let mut replaced = String::new(); let mut replaced = String::new();
for link in find_links(s) { for link in find_links(s) {
replaced.push_str(&s[previous_end_index..link.start_index]); let before_link = &s[previous_end_index..link.start_index];
let offset = if let Some(i) = before_link.rfind('\n') {
&before_link[i + 1..]
} else {
""
};
replaced.push_str(before_link);
match link.render_with_path(&path, chapter_title) { match link.render_with_path(&path, chapter_title) {
Ok(new_content) => { Ok(new_content) => {
if depth < MAX_LINK_NESTED_DEPTH { if depth < MAX_LINK_NESTED_DEPTH {
if let Some(rel_path) = link.link_type.relative_path(path) { if let Some(rel_path) = link.link_type.relative_path(path) {
replaced.push_str(&replace_all( let v =
&new_content, replace_all(&new_content, rel_path, source, depth + 1, chapter_title);
rel_path, let lines = v.split('\n').into_iter().collect::<Vec<&str>>();
source, // no need to add offset for the first line
depth + 1, replaced.push_str(lines[0]);
chapter_title, for line in lines.iter().skip(1) {
)); replaced.push_str(&format!("\n{}{}", &offset, &line));
}
} else { } else {
replaced.push_str(&new_content); replaced.push_str(&new_content);
} }

View File

@ -0,0 +1,2 @@
instance Eq (NonEmpty a) where
eq (NonEmpty x xs) (NonEmpty y ys) = x == y && xs == ys

View File

@ -29,3 +29,17 @@ assert!($TEST_STATUS);
```rust ```rust
{{#rustdoc_include partially-included-test-with-anchors.rs:rustdoc-include-anchor}} {{#rustdoc_include partially-included-test-with-anchors.rs:rustdoc-include-anchor}}
``` ```
## Keep Indent
1. The following code remains indent:
```haskell
{{#include ./eqNonEmpty.hs}}
```
we ...
1. The following code also remains indent:
```haskell
{{#include ./eqNonEmpty.hs}}
```
we ...

File diff suppressed because it is too large Load Diff