Skip to content

Extra newlines when combining unconditional and standard word wrapping #43

Open

Description

@meowgorithm

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.

Playground Example

Activity

  1. added
    bug
    on Jan 26, 2022
  2. bashbunni commented on Sep 14, 2023

    @bashbunni

    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

  3. janderland commented on Sep 17, 2023

    @janderland

    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.

  4. muesli commented on Sep 18, 2023

    @muesli
    Owner

    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.

  5. janderland commented on Sep 18, 2023

    @janderland

    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.

    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?

  6. janderland commented on Nov 5, 2023

    @janderland

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions