diff --git a/src/wrap.rs b/src/wrap.rs index 0eb8e45a..80552909 100644 --- a/src/wrap.rs +++ b/src/wrap.rs @@ -372,6 +372,15 @@ pub fn wrap_text(lines: &[String], width: usize) -> Vec { continue; } + let trimmed = line.trim(); + if trimmed.starts_with("") { + flush_paragraph(&mut out, &buf, &indent, width); + buf.clear(); + indent.clear(); + out.push(line.clone()); + continue; + } + if line.trim().is_empty() { flush_paragraph(&mut out, &buf, &indent, width); buf.clear(); diff --git a/tests/wrap.rs b/tests/wrap.rs index 08e1c3d3..4046a9cd 100644 --- a/tests/wrap.rs +++ b/tests/wrap.rs @@ -474,3 +474,36 @@ fn test_wrap_paragraph_with_nested_link() { "link with nested parentheses should remain intact", ); } + +/// Ensures that markdownlint directives remain on their own line when wrapping. +#[test] +fn test_markdownlint_directive_not_broken() { + let input = lines_vec![ + "[roadmap](./roadmap.md) and expands on the design ideas described in", + "", + ]; + let output = process_stream(&input); + assert_eq!(output, input); +} + +/// Regular comments should be reflowed like ordinary text when wrapping. +#[test] +fn test_regular_comment_wraps_normally() { + let input = lines_vec![ + "Intro text that preludes a lengthy comment.", + concat!( + "" + ), + ]; + let output = process_stream(&input); + assert_eq!( + output, + lines_vec![ + "Intro text that preludes a lengthy comment. ", + ] + ); +}