Skip to content

Instantly share code, notes, and snippets.

@willbroderick
Last active September 7, 2017 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willbroderick/390d8a9f733609fef1a135687cfa0ea2 to your computer and use it in GitHub Desktop.
Save willbroderick/390d8a9f733609fef1a135687cfa0ea2 to your computer and use it in GitHub Desktop.
Prevent a line-break before the last word in a passage of text, to aid typography
/*
* This will turn "I eat lots of poached eggs" into "I eat lots of poached eggs"
*
* So this:
* | I eat lots of poached |
* | eggs
*
* Becomes:
* | I eat lots of |
* | poached eggs |
*/
$('.menu a').each(function(){
var text = $(this).text();
text = text.replace(/([^\s]{1,8}) ([^\s]{1,16})$/, '$1 $2');
$(this).text(text);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment