Skip to content

Commit

Permalink
split before words too long
Browse files Browse the repository at this point in the history
  • Loading branch information
SichangHe committed May 25, 2024
1 parent 21a9a94 commit 0954738
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/paragraphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,25 @@ 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));
split_points.reset();
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));
Expand Down
6 changes: 6 additions & 0 deletions src/snapshots/fmtt__tests__long_link_long_description.snap
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 1 addition & 2 deletions src/snapshots/fmtt__tests__long_word.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
8 changes: 8 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0954738

Please sign in to comment.