Skip to content

Commit b9126fa

Browse files
committed
Do not format fenced code blocks in comment
1 parent c49526a commit b9126fa

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/comment.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ fn rewrite_comment_inner(
319319

320320
let mut result = opener.to_owned();
321321
let mut is_prev_line_multi_line = false;
322+
let mut inside_code_block = false;
322323
let comment_line_separator = format!("\n{}{}", indent_str, line_start);
323324
for line in lines {
324325
if result == opener {
@@ -331,6 +332,14 @@ fn rewrite_comment_inner(
331332
result.push_str(&comment_line_separator);
332333
}
333334

335+
if line.starts_with("```") {
336+
inside_code_block = !inside_code_block;
337+
}
338+
if inside_code_block {
339+
result.push_str(line);
340+
continue;
341+
}
342+
334343
if config.wrap_comments() && line.len() > fmt.shape.width && !has_url(line) {
335344
match rewrite_string(line, &fmt, Some(max_chars)) {
336345
Some(ref s) => {

0 commit comments

Comments
 (0)