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 small to inline elements. #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions typogr.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,20 @@
/**
* Wraps initial quotes in ``class="dquo"`` for double quotes or ``class="quo"``
* for single quotes. Works in these block tags ``(h1-h6, p, li, dt, dd)``
* and also accounts for potential opening inline elements ``a, em, strong, span, b, i``
* and also accounts for potential opening inline elements
* ``a, em, small, strong, span, b, i``
*
*/
var initQuotes = typogr.initQuotes = function(text) {
var re_quote = re(
'(?:(?:<(?:p|h[1-6]|li|dt|dd)[^>]*>|^)'+ // start with an opening
// p, h1-6, li, dd, dt
// or the start of the string
'\\s*'+ // optional white space!
'(?:<(?:a|em|span|strong|i|b)[^>]*>\\s*)*)'+//optional opening inline tags,
// with more optional white space for each.
'(?:("|&ldquo;|&#8220;)|'+ // Find me a quote! /only need to find
'(\'|&lsquo;|&#8216;))' // the left quotes and the primes/
'(?:(?:<(?:p|h[1-6]|li|dt|dd)[^>]*>|^)'+ // start with an opening
// p, h1-6, li, dd, dt
// or the start of the string
'\\s*'+ // optional white space!
'(?:<(?:a|em|small|span|strong|i|b)[^>]*>\\s*)*)'+ //optional opening inline tags,
// with more optional white space for each.
'(?:("|&ldquo;|&#8220;)|'+ // Find me a quote! /only need to find
'(\'|&lsquo;|&#8216;))' // the left quotes and the primes/
, 'i');

if( !text && typeof text !== "string" ) {
Expand All @@ -131,24 +132,24 @@
/**
* Replaces the space between the last two words in a string with ``&nbsp;``
* Works in these block tags ``(h1-h6, p, li, dd, dt)`` and also accounts for
* potential closing inline elements ``a, em, strong, span, b, i``
* potential closing inline elements ``a, em, small, strong, span, b, i``
*
*/
var widont = typogr.widont = function(text) {
var inline_tags = 'a|em|span|strong|i|b'
var inline_tags = 'a|em|small|span|strong|i|b'
var word = '(?:<(?:'+inline_tags+')[^>]*?>)*?[^\\s<>]+(?:</(?:'+inline_tags+')[^>]*?>)*?'
var re_widont = re(
'('+ // matching group 1
'\\s+'+word+ // space and a word with a possible bordering tag
'\\s+'+word+ // space and a word with a possible bordering tag
'('+ // matching group 1
'\\s+'+word+ // space and a word with a possible bordering tag
'\\s+'+word+ // space and a word with a possible bordering tag
')'+
'(?:\\s+)'+ // one or more space characters
'('+ // matching group 2
'[^<>\\s]+'+ // nontag/nonspace characters
'(?:\\s*</(?:a|em|span|strong|i|b)[^>]*?>\\s*\\.*)*?'+ // one or more inline closing tags
// can be surronded by spaces
// and followed by a period.
'(?:\\s*?</(?:p|h[1-6]|li|dt|dd)>|$)'+ // allowed closing tags or end of line
'(?:\\s+)'+ // one or more space characters
'('+ // matching group 2
'[^<>\\s]+'+ // nontag/nonspace characters
'(?:\\s*</(?:a|em|small|span|strong|i|b)[^>]*?>\\s*\\.*)*?'+ // one or more inline closing tags
// can be surronded by spaces
// and followed by a period.
'(?:\\s*?</(?:p|h[1-6]|li|dt|dd)>|$)'+ // allowed closing tags or end of line
')', 'gi');
return text.replace(re_widont, '$1<span class="widont">&nbsp;</span>$2');
};
Expand Down
2 changes: 1 addition & 1 deletion typogr.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.