-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Keep indent when using include in code block #1718
base: master
Are you sure you want to change the base?
Conversation
a1880e1
to
e22886a
Compare
Writing a book currently where I ran into the issue that is resolved in this PR. Are there any blockers for this to get merged? |
// no need to add offset for the first line | ||
replaced.push_str(lines[0]); | ||
for line in lines.iter().skip(1) { | ||
replaced.push_str(&format!("\n{}{}", &offset, &line)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could consider changing this to
replaced.push('\n');
replaced.push_str(&offset);
replaced.push_str(&line);
since you're simply concatenating strings.
)); | ||
let v = | ||
replace_all(&new_content, rel_path, source, depth + 1, chapter_title); | ||
let lines = v.split('\n').into_iter().collect::<Vec<&str>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're iterating over the lines one-by-one, you could iterate directly over the result of split
. So you would save the collect()
call be a tiny bit more efficient.
I tried to fix issue 1626. mdBook ignores the indent in code block created by #include. I think this is the reason why issue 1626 happened. So I implemented to add the offset to the code block created by #include.
fix: #1626