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

Option not to split words longer than a line #384

Closed
veikman opened this issue Jun 6, 2021 · 3 comments
Closed

Option not to split words longer than a line #384

veikman opened this issue Jun 6, 2021 · 3 comments

Comments

@veikman
Copy link

veikman commented Jun 6, 2021

As the documentation states, “NoHyphenation implements WordSplitter by not splitting the word at all.” However, textwrap::wrap effectively overrides the stated behaviour when the width of a word exceeds the configured maximum width of a line.

For contrast, Python provides a break_long_words option to allow individual words to exceed a given line width without being split. This allows long URLs, for example, to be preserved, which is useful.

As a Rust newbie, I would like to know what it would take to get that freedom in textwrap.

@veikman
Copy link
Author

veikman commented Jun 6, 2021

I now see there is a break_words option. Jolly good!

@veikman veikman closed this as completed Jun 6, 2021
@mgeisler
Copy link
Owner

mgeisler commented Jun 6, 2021

Hi @veikman, glad you found the break_words option! I've actually been wondering if I should rename it to break_long_words to make its function a bit clearer and also to keep the connection with Python's API.

@veikman
Copy link
Author

veikman commented Jun 7, 2021

Clarifying the documentation would be helpful; I don’t think you need to rename the option.

I now understand that although NoHyphenation is a WordSplitter, it does not split words (a paradox!), and although it does not split words, words are still split if it is chosen (by “breaking” in a separate stage, if break_words is true, independently of NoHyphenation; a separate paradox). The combination of these two paradoxes confused me.

I suggest making an explicit distinction, in the documentation of NoHyphenation and WordSplitter, between “splitting” (marking advantageous points within a word to decompose it, without breaking the language) and “breaking” (disregarding said points for higher-level reasons; breaking the language), and referring to break_words.

veikman added a commit to veikman/yamlwrap that referenced this issue Jul 10, 2021
Rebuilt the package on top of `punwrap`, removing the homegrown regex
logic and the passing of wordsplitters as parameters (this is the API
break), which `punwrap` cannot handle.

Results will be different.

At the time of this commit, this rebuild is known to cause some bad
behaviour; cf. mgeisler/textwrap#384.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants