Skip to content

Commit

Permalink
Merge pull request #228 from edwardloveall/el-bad-wrap
Browse files Browse the repository at this point in the history
Fix wrapping on lines succeeded by unwrappable lines
  • Loading branch information
kivikakk authored Jul 7, 2022
2 parents fb65615 + 54bb72c commit e23a579
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl<'a, 'o> CommonMarkFormatter<'a, 'o> {
}
}
self.column = 0;
self.last_breakable = 0;
self.begin_line = true;
self.begin_content = true;
self.need_cr -= 1;
Expand Down
33 changes: 33 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ fn compare_strs(output: &str, expected: &str, kind: &str) {
assert_eq!(output, expected);
}

#[track_caller]
fn commonmark(input: &str, expected: &str) {
let arena = ::Arena::new();
let mut options = ::ComrakOptions::default();
options.render.width = 72;

let root = ::parse_document(&arena, input, &options);
let mut output = vec![];
cm::format_document(root, &options, &mut output).unwrap();
compare_strs(&String::from_utf8(output).unwrap(), expected, "regular");
}

#[track_caller]
fn html(input: &str, expected: &str) {
html_opts(input, expected, |_| ());
Expand Down Expand Up @@ -249,6 +261,27 @@ fn thematic_breaks() {
);
}

#[test]
fn width_breaks() {
let input = concat!(
"this should break because it has breakable characters. break right here newline\n",
"\n",
"don't break\n",
"\n",
"a-long-line-that-won't-break-because-there-is-no-character-it-can-break-on\n"
);
let output = concat!(
"this should break because it has breakable characters. break right here\n",
"newline\n",
"\n",
"don't break\n",
"\n",
"a-long-line-that-won't-break-because-there-is-no-character-it-can-break-on\n"
);

commonmark(input, output);
}

#[test]
fn setext_heading() {
html(
Expand Down

0 comments on commit e23a579

Please sign in to comment.