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 titles with javascript #41

Open
mxdubois opened this issue Aug 16, 2014 · 6 comments
Open

Prevent widows in titles with javascript #41

mxdubois opened this issue Aug 16, 2014 · 6 comments

Comments

@mxdubois
Copy link
Contributor

by adapting this function:
http://css-tricks.com/snippets/jquery/add-non-breaking-space-on-title-to-prevent-widows/

As is, it removes the links in the ToC h2s, but I bet it can be improved.

@mxdubois
Copy link
Contributor Author

Ah, this one comes from further down in the comments. It works without problems.

$("h2").html(function(i, text){ 
    return text
        .replace(/\ ([^\s]+)$/,' $1')
        .replace(/\s([^\s]+)\s*$/,' $1')
 })

@mxdubois
Copy link
Contributor Author

We could do this for paragraphs too, if we wanted to be perfectionists. I don't think the performance impact would be noticeable next to MathJax. We'd have to test it on a long document (many paragraphs) with MathJax disabled to be sure.

@rbeezer
Copy link

rbeezer commented Aug 17, 2014

Nice idea for titles. But it strikes me as overkill for paragraphs.

What if a title has math in it like "A theorem about $x^2 y^2$"? Would the nbsp totally fubar the MathJax application to the product?

@mxdubois
Copy link
Contributor Author

That's a good point. I bet it would screw that up. With some careful thought, I bet the function could be adapted to avoid that situation.

I get the suspicion David is good with regular expressions. Maybe he could give it a shot?

@rbeezer
Copy link

rbeezer commented Aug 18, 2014

I get the suspicion David is good with regular expressions.

He's the best.

@davidfarmer
Copy link
Contributor

The idea of "put a non-breaking space when the last word is short"
is a good one, but if the title is writen in LaTeX then there are
too many crazy possibilities. For example:

 On a Theorem of Erd\H os

Some people even put hard returns (LaTeX ) in their titles.

If you knew that math was the only exception to handle (so the above
example was converted to unicode), then it wouldn't be too hard to
write a regular expression that handles most cases.

On Sun, 17 Aug 2014, Michael DuBois wrote:

That's a good point. I bet it would screw that up. With some careful thought, I bet the function could be adapted to avoid that situation.

I get the suspicion David is good with regular expressions. Maybe he could give it a shot?


Reply to this email directly or view it onGitHub.[211500__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyMzk1NzcyNSwiZGF0YSI6eyJpZCI6Mzk4NjA0OTJ9fQ==--c289b197ddfa4d754c594400a484be9330
4c186d.gif]

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

No branches or pull requests

3 participants