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

Add 'justify' as an option for text alignment #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

brianchirls
Copy link

Spaces text so each line fills the entire width.

There is one area I'd like to suggest for future improvement, which is how trailing lines are handled. In my experience, you don't want to justify the last line of a paragraph. (See, for example, Star Wars opening crawls.) To implement this properly, we'd need to know whether each line was forced to wrap or ended naturally by EOL or EOF. But https://github.com/mattdesl/word-wrapper strips that information out. So for now, I've chosen to justify only lines that take up 70% of the line width.

If @mattdesl would like to make a change to include an additional boolean in the output of word-wrapper, I'd be happy to make another commit or PR here.

@mattdesl
Copy link
Contributor

Thanks! This is great.

I am wondering if there is a more robust algorithm we can apply here, or in the child word-wrapper module. Maybe using linebreak to handle proper Unicode line breaking. I have not read much about justify and 70% seems a bit arbitrary... is it standard? Are there some suggested algorithms for handling justify?

@brianchirls
Copy link
Author

brianchirls commented May 16, 2017 via email

@brianchirls
Copy link
Author

@mattdesl I made a pull request over at word-wrapper. If you can review and accept that, I'll update this one to include better logic for aligning that last line. Thanks.

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

Successfully merging this pull request may close these issues.

2 participants