diff --git a/src/paragraphs.rs b/src/paragraphs.rs index e3d2620..b947694 100644 --- a/src/paragraphs.rs +++ b/src/paragraphs.rs @@ -183,9 +183,10 @@ impl<'a> Paragraph<'a> { if n_char <= line_width || to_be_split.is_empty() { break; } - match split_points.next() { - None => { - // No valid split point found. + match (split_len >= line_width, split_points.next()) { + (true, _) | (_, None) => { + // Either the new split is too longer, + // or no valid split point was found. // Drain the entire buffer once. let last_index = to_be_split.len().saturating_sub(1); push_line!(to_be_split.drain(..last_index)); @@ -193,11 +194,14 @@ impl<'a> Paragraph<'a> { n_char = split_len; break; } - Some( - split_point @ SplitPoint { - index, - n_char_after, - }, + ( + _, + Some( + split_point @ SplitPoint { + index, + n_char_after, + }, + ), ) => { trace!(?split_point, "next"); push_line!(to_be_split.drain(..index)); diff --git a/src/snapshots/fmtt__tests__long_link_long_description.snap b/src/snapshots/fmtt__tests__long_link_long_description.snap new file mode 100644 index 0000000..64afe33 --- /dev/null +++ b/src/snapshots/fmtt__tests__long_link_long_description.snap @@ -0,0 +1,6 @@ +--- +source: src/tests.rs +expression: "&formatted" +--- +![Math for hue-grayscale to RGB conversion on a +whiteboard](https://github.com/SichangHe/internet_route_verification/assets/84777573/11f8ad38-403c-4e5d-99da-66176795223f) diff --git a/src/snapshots/fmtt__tests__long_word.snap b/src/snapshots/fmtt__tests__long_word.snap index 1d47562..2045f52 100644 --- a/src/snapshots/fmtt__tests__long_word.snap +++ b/src/snapshots/fmtt__tests__long_word.snap @@ -2,6 +2,5 @@ source: src/tests.rs expression: "&formatted" --- -But, -it chokes at very long splits such as +But, it chokes at very long splits such as `this_function_does_absolutely_nothing_i_am_afraid_but_it_needs_to_be_here_or_the_program_breaks`. diff --git a/src/tests.rs b/src/tests.rs index dc951f8..6f462c7 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -60,6 +60,14 @@ fn long_link() { assert_snapshot!(&formatted); } +#[test] +fn long_link_long_description() { + init_tracing(); + let input = "![Math for hue-grayscale to RGB conversion on a whiteboard](https://github.com/SichangHe/internet_route_verification/assets/84777573/11f8ad38-403c-4e5d-99da-66176795223f)"; + let formatted = default_format(input); + assert_snapshot!(&formatted); +} + #[test] fn gpt1() { init_tracing();