minimize
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -24,3 +24,3 @@ 'use strict'; | ||
, structural = /pre|textarea/ | ||
, interpunction = /^[\.,!%;:\-]/; | ||
, interpunction = /[\.,!%;:\-\?]/; | ||
@@ -37,2 +37,9 @@ /** | ||
/** | ||
* Helper constructor. | ||
* | ||
* @Constructor | ||
* @param {Object} options | ||
* @api public | ||
*/ | ||
function Helpers (options) { | ||
@@ -62,3 +69,5 @@ if (options) config = util.mixin(config, options); | ||
Helpers.prototype.tag = function tag (element, ancestor, data) { | ||
return (this.isInline(element) && flow.test(data) ? ' <' : '<') + element.data + '>'; | ||
return (this.isInline(element) && (flow.test(data) || interpunction.test(data)) | ||
? ' <' | ||
: '<') + element.data + '>'; | ||
}; | ||
@@ -121,3 +130,5 @@ | ||
if (!this.structure(ancestor)) element = element.replace(/\n/g, '').replace(/\s+/g, ' '); | ||
if (flow.test(data) && !interpunction.test(element)) element = ' ' + element; | ||
if (flow.test(data) && !(new RegExp('^' + interpunction.source)).test(element)) { | ||
element = ' ' + element; | ||
} | ||
@@ -124,0 +135,0 @@ return element; |
{ | ||
"name": "minimize", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Minimize HTML", | ||
@@ -5,0 +5,0 @@ "main": "./lib/minimize", |
{ | ||
"content": "<div class=\"slide nodejs\">\n <h3>100% Node.js</h3>\n <p>\n We are Node.js experts and the first hosting platform to build\n our full stack in node. We understand your node application\n better than anyone.\n </p>\n </div>\n\n " | ||
, "comment": "<!-- some HTML comment -->\n <div class=\"slide nodejs\">\n <h3>100% Node.js</h3>\n <p>\n We are Node.js experts and the first hosting platform to build\n our full stack in node. We understand your node application\n better than anyone.\n </p>\n </div>\n\n " | ||
, "interpunction": "<h3>Become a partner</h3>\n <p>\n Interested in being part of the solution?\n <a href=\"/company/contact\">Contact Nodejitsu to discuss</a>.\n </p>" | ||
, "doctype": { | ||
@@ -5,0 +6,0 @@ "raw": "!doctype html" |
@@ -74,2 +74,9 @@ 'use strict'; | ||
it('should handle inline flow properly', function (done) { | ||
minimize.minimize(html.interpunction, function (result) { | ||
expect(result).to.equal('<h3>Become a partner</h3><p>Interested in being part of the solution? <a href="/company/contact">Contact Nodejitsu to discuss</a>.</p>'); | ||
done(); | ||
}); | ||
}); | ||
it('should be configurable to retain comments', function (done) { | ||
@@ -76,0 +83,0 @@ minimize.minimize(html.comment, function (result) { |
27123
697