public static function Typogrify::widont in Typogrify 7
Same name and namespace in other branches
- 5 typogrify.class.php \Typogrify::widont()
- 6 typogrify.class.php \Typogrify::widont()
widont
Replaces the space between the last two words in a string with `` `` Works in these block tags ``(h1-h6, p, li)`` and also accounts for potential closing inline elements ``a, em, strong, span, b, i``
Empty HTMLs shouldn't error
3 calls to Typogrify::widont()
- Typogrify::filter in ./
typogrify.class.php - typogrify
- TypogrifyClassTestCase::testWidont in tests/
typogrify.class.test - Widont test.
- _typogrify_process in ./
typogrify.module - Processing function to apply the Typogrify filters.
File
- ./
typogrify.class.php, line 159 - typogrify.class.php Defines a class for providing different typographical tweaks to HTML
Class
- Typogrify
- @file typogrify.class.php Defines a class for providing different typographical tweaks to HTML
Code
public static function widont($text) {
// This regex is a beast, tread lightly
$widont_finder = "/([^<>\\s]+|<\\/span>) # ensure more than 1 word\n (\\s+) # the space to replace\n ([^<>\\s]+ # must be flollowed by non-tag non-space characters\n \\s* # optional white space!\n (<\\/(a|em|span|strong|i|b)[^>]*>\\s*)* # optional closing inline tags with optional white space after each\n ((<\\/(p|h[1-6]|li|dt|dd)>)|\$)) # end with a closing p, h1-6, li or the end of the string\n /x";
return preg_replace($widont_finder, '$1 $3', $text);
}