Skip to content

Commit caed120

Browse files
authored
Merge pull request #2332 from adhoore/bugfix/code-block-newlines
markdown: Fix indentation of multi-line code blocks
2 parents 3228ba9 + 6c043a3 commit caed120

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/cli/markdown.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ impl<'a, T: Terminal + 'a> LineWrapper<'a, T> {
7272
self.write_word(word);
7373
}
7474
}
75+
// Writes code block where each line is indented
76+
fn write_code_block(&mut self, text: &str) {
77+
for line in text.lines() {
78+
self.write_word(line); // Will call write_indent()
79+
self.write_line();
80+
}
81+
}
7582
// Constructor
7683
fn new(w: &'a mut T, indent: u32, margin: u32) -> Self {
7784
LineWrapper {
@@ -188,7 +195,7 @@ impl<'a, T: Terminal + io::Write + 'a> LineFormatter<'a, T> {
188195
End(tag) => self.end_tag(tag),
189196
Text(text) => {
190197
if self.is_code_block {
191-
self.wrapper.write_word(&text);
198+
self.wrapper.write_code_block(&text);
192199
} else {
193200
self.wrapper.write_span(&text);
194201
}

0 commit comments

Comments
 (0)