From 21fdaa4f2d851c8fa8c29c4a7a087041a2a4121d Mon Sep 17 00:00:00 2001
From: Matthew Lyon
In a couple of paragraphs
paragraph two
'), 'In a couple of paragraphs
paragraph two
'); assert.equal(tp.widont('Three Four Five
" or html tags with spaces in them for attributes. --- test/typogr.test.js | 4 ++-- typogr.js | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/typogr.test.js b/test/typogr.test.js index cb284fb..4f3e182 100644 --- a/test/typogr.test.js +++ b/test/typogr.test.js @@ -57,8 +57,8 @@ module.exports = { assert.equal(tp.widont('In a couple of paragraphs
paragraph two
'), - 'In a couple of paragraphs
paragraph two
'); + assert.equal(tp.widont('In a couple of paragraphs
the paragraph number two
'), + 'In a couple of paragraphs
the paragraph number two
'); assert.equal(tp.widont('In a couple of paragraphs
the paragraph number two
'), 'In a couple of paragraphs
the paragraph number two
'); diff --git a/typogr.js b/typogr.js index 826501e..62a506f 100644 --- a/typogr.js +++ b/typogr.js @@ -134,8 +134,13 @@ * */ var widont = typogr.widont = function(text) { + var inline_tags = 'a|em|span|strong|i|b' + var word = '(?:<(?:'+inline_tags+')[^>]*?>)*?[^\\s<>]+(?:(?:'+inline_tags+')[^>]*?>)*?' var re_widont = re( - '(\\s+[^\\s]+\\s+[^\\s]+)'+ // matching group 1: two words preceeded by space, need four words to trigger + '('+ // 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