jonschlinkert / word-wrap

Wrap words to a specified length.
https://github.com/jonschlinkert
MIT License
194 stars 57 forks source link

Add options to break words if encounters long words. #8

Closed terrencekhng closed 9 years ago

terrencekhng commented 9 years ago

When we meet a paragraph contains some very long words:

this is a veryveryveryveryveryveryverylonglongloooooongword, what should we do to handle this veryveryveryveryverylooooongword?

Should it look like this under specific width:

this is a veryveryveryveryveryveryvery-
longlongloooooongword, what should 
we do to handle this veryveryveryvery-
verylooooongword?
jonschlinkert commented 9 years ago

hmm, that's an interesting challenge. I'll try to come up with something

danilosampaio commented 9 years ago

hi @jonschlinkert

a simpler feature would be cuttting the words longer then width, when the cut option is true:

var re = new RegExp('.{1,' + width + '}(\\s+|$)|\\S+?(\\s+|$)', 'g');

if (opts.cut) {
    re = new RegExp('.{1,' + width + '}', 'g');
}

interested in a PR?

jonschlinkert commented 9 years ago

makes sense, a PR would be great. thanks!

jonschlinkert commented 9 years ago

closed via https://github.com/jonschlinkert/word-wrap/issues/9.

thanks @danilosampaio! https://github.com/jonschlinkert/word-wrap/releases/tag/1.1.0

danilosampaio commented 9 years ago

nice! :+1: