Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapping multiline text #27

Open
fcastilloec opened this issue Dec 15, 2017 · 1 comment · May be fixed by #61
Open

Wrapping multiline text #27

fcastilloec opened this issue Dec 15, 2017 · 1 comment · May be fixed by #61

Comments

@fcastilloec
Copy link

I'm having trouble understanding how this module works with multiline text and I feel the current behavior has a bug.
Here's an example:

const wrap = require('word-wrap')
const test = `Highlights:\n First\n Second\n Third`

result = wrap(test, {width: 80}, indent: '*');

The output I get is *Highlights:\n \n*First\n \n*Second\n \n*Third but what I expected was *Highlights:\n\n* First\n\n* Second\n\n* Third. Why are the spaces after a newline being included in the previous line? Is this a bug?

@Deide
Copy link

Deide commented Aug 31, 2018

Shouldn't it return *Highlights:\n* First\n* Second\n* Third? Why would it add more line breaks to lines that are already below a width of 80? In fact, that is what it does if there's not a space after the newline - seems like a bug to behave this way when there's a space. Maybe there should be an option to trim each line; I think the current trim just does the whole thing.

Other than that, there are also cases where it's desirable to have the indent added on blank lines (for example, when you have "\n\n" in the source text).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants
@fcastilloec @Deide and others