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

Prevent widows in descriptions #88

Merged
merged 1 commit into from Feb 1, 2016
Merged

Conversation

@fofr
Copy link
Contributor

@fofr fofr commented Feb 1, 2016

Stop widows by putting a   between the last two words in a description

Before

screen shot 2016-02-01 at 16 21 34

After

screen shot 2016-02-01 at 16 21 43

* Create a typography helper
* Stop widows by putting a `nbsp` between the last two words in a
description
* Accept trailing punctuation when adding nbsp
gpeng added a commit that referenced this pull request Feb 1, 2016
Prevent widows in descriptions
@gpeng gpeng merged commit a7b688f into master Feb 1, 2016
1 check passed
1 check passed
default Build #370 succeeded on Jenkins
Details
@gpeng gpeng deleted the prevent-widows-in-descriptions branch Feb 1, 2016
@@ -0,0 +1,5 @@
module TypographyHelper
def nbsp_between_last_two_words(text)
text.sub(/\s([\w\.\?\!]+)$/, ' \1').html_safe

This comment has been minimized.

@dsingleton

dsingleton Feb 2, 2016
Contributor

It would be good to have a test that would assert what happens if the text input included markup, eg:

assert_equal "this &lt;b&gt;&nbsp;&lt;/b&gt; that", nbsp_between_last_two_words("this <b>and</b> that")

I think there's a escaping bug and the <b> will be marked as safe. Even if it isn't a bug, it would be good for the test to cover that case if the implementation changed, and to self-document. It's reasonable to expect a description to include & or < and for those not to break rendering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.