Skip to content
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

Fix wrapping on lines succeeded by unwrappable lines #228

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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