Skip to content

Commit

Permalink
[fix] remove non-inline and obselete HTML5 elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Swaagie committed Jul 24, 2013
1 parent ea4f71b commit bcbff0f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.5.9
- [Fix] No space between inline elements that don't need it
- [Minor] Remove obsolete HTML5 elements or superfluous inline elements

## v0.5.4
- [Fix] Update dependencies

Expand Down
8 changes: 4 additions & 4 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ var util = require('utile');
*/
var flow = /<\/[^>]+>$|\w+$/
, inline = [
'a', 'abbr', 'acronym', 'b', 'bdo', 'big', 'br', 'button', 'cite'
, 'code', 'dfn', 'em', 'i', 'img', 'input', 'kbd', 'label', 'map'
, 'object', 'q', 'samp', 'script', 'select', 'small', 'span', 'strong'
, 'sub', 'sup', 'textarea', 'tt', 'var'
'a', 'abbr', 'b', 'bdo', 'br', 'cite'
, 'code', 'dfn', 'em', 'i', 'img', 'kbd'
, 'q', 'samp', 'small', 'span', 'strong'
, 'sub', 'sup', 'textarea', 'var'
]
, singular = [
'area', 'base', 'br', 'col', 'command', 'embed', 'hr'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minimize",
"version": "0.5.8",
"version": "0.5.9",
"description": "Minimize HTML",
"main": "./lib/minimize",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/html.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
, "cdata": "<script type=\"text/javascript\">\n//<![CDATA[\n...code...\n//]]>\n</script>"
, "noscript": "<script type=\"imno/script\" id=plates-forgot><h3>\n Forgot your password?\n <a href=\"#\" class=\"close ss-delete\"></a>\n </h3>\n\n <p>Tell us your username and we will reset it for you.</p>\n\n <p class=\"error alert\"></p>\n <p class=\"success alert\"></p></script>"
, "empty": "<h1 class=\"slide nodejs\">a</h1><h2 name=\"\">b</h2><h3 id=\"lol\">c</h3><h4 disabled=\"disabled\">d</h4><h5 autofocus=true>e</h5><h6 itemscope>f</h6>"
, "scripts": "<script type=text/javascript src=//use.typekit.net/gmp8svh.js></script> <script type=text/javascript>"
, "doctype": {
"data": "!doctype html"
, "type": "directive"
Expand Down
4 changes: 2 additions & 2 deletions test/helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('Helpers', function () {
});

it('calls helpers#attributes once and appends content behind name', function () {
expect(helpers.tag(html.singular)).to.be.equal(' <input type=text name=temp>');
expect(helpers.tag(html.singular)).to.be.equal('<input type=text name=temp>');

expect(attr).to.be.calledAfter(structure);
expect(attr).to.be.calledOnce;
Expand Down Expand Up @@ -426,7 +426,7 @@ describe('Helpers', function () {
});

it('has all required elements', function () {
expect(helpers.inline.length).to.be.equal(31);
expect(helpers.inline.length).to.be.equal(21);
});
});

Expand Down
11 changes: 9 additions & 2 deletions test/minimize-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,16 @@ describe('Minimize', function () {
});
});

it('should parse the full stack', function (done) {
it('should not prepend spaces between inline elements if not required', function (done) {
minimize.parse(html.scripts, function (error, result) {
expect(result).to.equal("<script type=text/javascript src=//use.typekit.net/gmp8svh.js></script><script type=text/javascript></script>");
done();
});
});

it('should parse the full stack', function (done) {
minimize.parse(html.full, function (error, result) {
expect(result).to.equal("<!doctype html><html class=no-js><head></head><body class=container><section class=navigation id=navigation><nav class=row><h1><a href=/ class=logo title=\"Back to the homepage\">Nodejitsu</a></h1> <a href=#navigation class=\"mobile btn ss-rows\"></a> <a href=/paas>Cloud</a> <a href=/enterprise/private-cloud>Enterprise</a></nav></section> <input type=text name=temp></body></html>");
expect(result).to.equal("<!doctype html><html class=no-js><head></head><body class=container><section class=navigation id=navigation><nav class=row><h1><a href=/ class=logo title=\"Back to the homepage\">Nodejitsu</a></h1> <a href=#navigation class=\"mobile btn ss-rows\"></a> <a href=/paas>Cloud</a> <a href=/enterprise/private-cloud>Enterprise</a></nav></section><input type=text name=temp></body></html>");
done();
});
});
Expand Down

0 comments on commit bcbff0f

Please sign in to comment.