ensure \n\n are kept as \n\n
When splitting `'foo\n\nbar'` by `\n`, you will get `['foo', '', 'bar']`. The `''` value will result in `[]` after the word wrapping. This information gets lost when we `flatMap`, so let's keep the newline using `['']` as the fallback.
This commit is contained in:
parent
be10cf4474
commit
1d1535af90
1 changed files with 1 additions and 1 deletions
|
|
@ -44,7 +44,7 @@ export function wordWrap(text: string, width: number): string[] {
|
|||
// Handle text with newlines by maintaining the newlines, then splitting
|
||||
// each line separately.
|
||||
if (text.includes('\n')) {
|
||||
return text.split('\n').flatMap((line) => wordWrap(line, width))
|
||||
return text.split('\n').flatMap((line) => (line ? wordWrap(line, width) : ['']))
|
||||
}
|
||||
|
||||
let words = text.split(' ')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue