Comparing version 0.0.5 to 0.0.6
'use strict'; | ||
function tag (element) { | ||
return '<' + element.data + '>'; | ||
var flow = /<\/[^>]+>$|\w+$/ | ||
, inline = [ | ||
'b', 'big', 'i', 'small', 'tt', 'abbr', 'acronym', 'cite', 'code', 'dfn' | ||
, 'em', 'kbd', 'strong', 'samp', 'var', 'a', 'bdo', 'br', 'img', 'map' | ||
, 'object', 'q', 'script', 'span', 'sub', 'sup', 'button', 'input', 'label' | ||
, 'select', 'textarea' | ||
]; | ||
function isInline (element) { | ||
return !!~inline.indexOf(element.name); | ||
} | ||
function tag (element, ancestor, data) { | ||
return (isInline(element) && data.match(flow) ? ' <' : '<') + element.data + '>'; | ||
} | ||
function close (element) { | ||
@@ -18,3 +30,3 @@ return element.type === 'tag' || element.type === 'script' | ||
function requiresFlow(element) { | ||
function structure(element) { | ||
return element.type !== 'text' | ||
@@ -25,8 +37,10 @@ ? element.name.match(/pre|textarea/) || isJS(element) | ||
function text (element, parent) { | ||
element = element.data; | ||
function text (element, ancestor, data) { | ||
element = element.data.trim(); | ||
if (!requiresFlow(parent)) element = element.replace(/\n/, '').replace(/\s+/g, ' '); | ||
if (!structure(ancestor)) element = element.replace(/\n/, '').replace(/\s+/g, ' '); | ||
return element.trim(); | ||
if (data.match(flow)) element = ' ' + element; | ||
return element; | ||
} | ||
@@ -36,8 +50,6 @@ | ||
close: close | ||
, map: { | ||
directive: tag | ||
, tag: tag | ||
, text: text | ||
, script: tag | ||
} | ||
, directive: tag | ||
, tag: tag | ||
, text: text | ||
, script: tag | ||
}; | ||
@@ -50,5 +62,6 @@ | ||
module.exports.tag = tag; | ||
module.exports.text = text; | ||
module.exports.text = isJS; | ||
module.exports.text = requiresFlow; | ||
module.exports.isJS = isJS; | ||
module.exports.structure = structure; | ||
module.exports.isInline = isInline; | ||
module.exports.flow = flow; | ||
} |
@@ -8,3 +8,3 @@ 'use strict'; | ||
, htmlparser | ||
, previous; | ||
, ancestor; | ||
@@ -30,5 +30,7 @@ /** | ||
function walk (data, element) { | ||
data += helpers.map[element.type](element, previous); | ||
previous = element; | ||
data += helpers[element.type](element, ancestor, data); | ||
// Store reference to ancestor. | ||
if (element.children) ancestor = element; | ||
return (element.children | ||
@@ -35,0 +37,0 @@ ? traverse(element.children, data) |
{ | ||
"name": "minimize", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Minimize HTML", | ||
@@ -5,0 +5,0 @@ "main": "./lib/minimize", |
@@ -27,2 +27,10 @@ 'use strict'; | ||
}); | ||
describe('prepends a space if the element', function () { | ||
it('is inline and prepended by text', function () { | ||
}); | ||
it('is inlnie and prepended by closing tag', function () { | ||
}); | ||
}); | ||
}); | ||
@@ -55,3 +63,3 @@ | ||
describe('function requiresFlow', function () { | ||
describe('function structure', function () { | ||
it('returns false if element is text', function () { | ||
@@ -66,2 +74,35 @@ }); | ||
}); | ||
describe('function text', function () { | ||
it('trims whitespace', function () { | ||
}); | ||
it('replaces whitelines and spaces in non structural elements', function () { | ||
}); | ||
it('retains structure if element requires structure', function () { | ||
}); | ||
it('prepends space if the text is prepended with closing tag', function () { | ||
}); | ||
}); | ||
describe('inline element list', function () { | ||
it('is an array', function () { | ||
}); | ||
it('has all required elements', function () { | ||
}); | ||
}); | ||
describe('regular expression flow', function () { | ||
it('is a valid regular expression', function () { | ||
}); | ||
it('can detect if last part of string is closing tag', function () { | ||
}); | ||
it('can detect if last part of string is text', function () { | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23448
212