diff --git a/src/glint/internal/utils.gleam b/src/glint/internal/utils.gleam index bd6da2b..7ab2927 100644 --- a/src/glint/internal/utils.gleam +++ b/src/glint/internal/utils.gleam @@ -78,38 +78,21 @@ fn do_space_split_lines( // base case [], _, _ -> acc // the start of a chain of newlines - // set the flag to true ["\n", "\n", ..rest], _, False -> do_space_split_lines(rest, #(acc.0, True)) - // a continued chain of new lines, but no values have been accumulated yet - // this shouldnt be possible but we handle it anyway - ["\n", "\n", ..rest], [], True -> do_space_split_lines(rest, #([], True)) - // a continued chain of new lines - // add a newline to the most recent accumulated value - ["\n", "\n", ..rest], [s, ..accs], True -> - do_space_split_lines(["\n", ..rest], #([s <> "\n", ..accs], True)) - // a single newline in a chain of newlines, but no values have been accumulated yet - // this shouldnt be possible but we handle it anyway - ["\n", ..rest], [], True -> do_space_split_lines(rest, #([], True)) - // a single newline in a chain - // add a newline to the most recent accumulated value + // // a single newline in a chain, add a newline to the accumulator ["\n", ..rest], [s, ..accs], True -> do_space_split_lines(rest, #([s <> "\n", ..accs], True)) - // a single newline on its own but with no accumulated values yet - // skip it - ["\n", ..rest], [], False -> do_space_split_lines(rest, #([], False)) - // a single newline on its own - // add a space to the most recent accumulated value + // a single newline on its own, add a space to the most recent accumulated value ["\n", ..rest], [s, ..accs], False -> do_space_split_lines(rest, #([s <> " ", ..accs], False)) - // a non-newline character after a chain of newlines - // start a new accumulated value - [c, ..rest], _, True -> do_space_split_lines(rest, #([c, ..acc.0], False)) - // a non-newline character not after a chain of newlines, with no accumulated values - // add it as a new accumulated value - [c, ..rest], [], False -> do_space_split_lines(rest, #([c], False)) + // a single new line part of a chain with no accumulated values yet + // skip it + ["\n", ..rest], [], chain -> do_space_split_lines(rest, #([], chain)) // a non-newline character not after a chain of newlines // add it to the end of the most recent accumulated value [c, ..rest], [s, ..accs], False -> do_space_split_lines(rest, #([s <> c, ..accs], False)) + // a non-newline character, create a new accumulated value + [c, ..rest], _, _ -> do_space_split_lines(rest, #([c, ..acc.0], False)) } }