reflow
reflow copied to clipboard
Extra newlines when combining unconditional and standard word wrapping
When combining word-wrapping with unconditional wrapping as described in the README, extra linebreaks can sometimes be found in the output.
For example:
const str = "the quick brown foxxxxxxxxxxxxxxxx jumped over the lazy dog."
const limit = 16
wrapped := wrap.String(wordwrap.String(str, limit), limit)
fmt.Println(wrapped)
Outputs:
the quick brown
foxxxxxxxxxxxxxx
xx
jumped over the
lazy dog.
However, I'd expect it to be:
the quick brown
foxxxxxxxxxxxxxx
xx jumped over
the lazy dog.
We could probably enhance wordwrap to include forceful newlines to break words at the given width. The wrapper is behaving as expected in this case. (New lines are preserved by default) https://github.com/bashbunni/reflow/blob/master/wrap/wrap.go#L36
I'm also running into this issue. I may be able to take a stab at implementing what @bashbunni is describing if she isn't doing so already.
I'm also running into this issue. I may be able to take a stab at implementing what @bashbunni is describing if she isn't doing so already.
Depending on what you actually need, you can also just initialize a new wrap.Writer
and set PreserveNewlines
to false
.
I'm also running into this issue. I may be able to take a stab at implementing what @bashbunni is describing if she isn't doing so already.
Depending on what you actually need, you can also just initialize a new
wrap.Writer
and setPreserveNewlines
tofalse
.
By setting wrap.Wrap.PreserveNewlines
to false
, won't this cause wrap.Wrap
to undo the work which wordwrap.Wrap
did? wordwrap.Wrap
is only adding newlines to the string. If we don't preserve them it will be as if wordwrap.Wrap
never modified the original string, right?
OK, I took a stab at adding this feature the library but ran into some problems while trying to maintain the current functionality. To better wrap my head around the problem, I implemented the wrapping functionality I need in my own project. I'm still open to porting this functionality back into this project if it's something the author wants.