"semi-spacing": "error",
"space-before-blocks": "error",
"space-unary-ops": "error",
+ "space-in-parens": "error",
"spaced-comment": [
"error",
"always",
function setCheckedAttrOnCheckboxes(attrValue) {
var checkboxes = byId('options').getElementsByTagName('input');
- for (var i = checkboxes.length; i--; ) {
+ for (var i = checkboxes.length; i--;) {
checkboxes[i].checked = attrValue;
}
}
+ '\\s*(?:' + singleAttrValues.join('|') + '))?';
if (handler.customAttrSurround) {
var attrClauses = [];
- for ( var i = handler.customAttrSurround.length - 1; i >= 0; i-- ) {
+ for (var i = handler.customAttrSurround.length - 1; i >= 0; i--) {
attrClauses[i] = '(?:'
+ '(' + handler.customAttrSurround[i][0].source + ')\\s*'
+ pattern
return new RegExp('^\\s*' + pattern);
}
-function joinSingleAttrAssigns( handler ) {
+function joinSingleAttrAssigns(handler) {
return singleAttrAssigns.concat(
handler.customAttrAssign || []
).map(function (assign) {
}).join('|');
}
-function HTMLParser( html, handler ) {
+function HTMLParser(html, handler) {
var stack = [], lastTag;
var attribute = attrForHandler(handler);
var last, prevTag, nextTag;
- while ( html ) {
+ while (html) {
last = html;
// Make sure we're not in a script or style element
- if ( !lastTag || !special(lastTag) ) {
+ if (!lastTag || !special(lastTag)) {
var textEnd = html.indexOf('<');
if (textEnd === 0) {
// Comment:
- if ( /^<!--/.test( html ) ) {
+ if (/^<!--/.test(html)) {
var commentEnd = html.indexOf('-->');
- if ( commentEnd >= 0 ) {
- if ( handler.comment ) {
- handler.comment( html.substring( 4, commentEnd ) );
+ if (commentEnd >= 0) {
+ if (handler.comment) {
+ handler.comment(html.substring(4, commentEnd));
}
- html = html.substring( commentEnd + 3 );
+ html = html.substring(commentEnd + 3);
prevTag = '';
continue;
}
}
// http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment
- if ( /^<!\[/.test( html ) ) {
+ if (/^<!\[/.test(html)) {
var conditionalEnd = html.indexOf(']>');
if (conditionalEnd >= 0) {
- if ( handler.comment ) {
- handler.comment( html.substring(2, conditionalEnd + 1 ), true /* non-standard */ );
+ if (handler.comment) {
+ handler.comment(html.substring(2, conditionalEnd + 1), true /* non-standard */);
}
- html = html.substring( conditionalEnd + 2 );
+ html = html.substring(conditionalEnd + 2);
prevTag = '';
continue;
}
}
// Doctype:
- var doctypeMatch = html.match( doctype );
- if ( doctypeMatch ) {
- if ( handler.doctype ) {
- handler.doctype( doctypeMatch[0] );
+ var doctypeMatch = html.match(doctype);
+ if (doctypeMatch) {
+ if (handler.doctype) {
+ handler.doctype(doctypeMatch[0]);
}
- html = html.substring( doctypeMatch[0].length );
+ html = html.substring(doctypeMatch[0].length);
prevTag = '';
continue;
}
// End tag:
- var endTagMatch = html.match( endTag );
- if ( endTagMatch ) {
- html = html.substring( endTagMatch[0].length );
- endTagMatch[0].replace( endTag, parseEndTag );
+ var endTagMatch = html.match(endTag);
+ if (endTagMatch) {
+ html = html.substring(endTagMatch[0].length);
+ endTagMatch[0].replace(endTag, parseEndTag);
prevTag = '/' + endTagMatch[1].toLowerCase();
continue;
}
// Start tag:
var startTagMatch = parseStartTag(html);
- if ( startTagMatch ) {
+ if (startTagMatch) {
html = startTagMatch.rest;
handleStartTag(startTagMatch);
prevTag = startTagMatch.tagName.toLowerCase();
var text;
if (textEnd >= 0) {
- text = html.substring( 0, textEnd );
- html = html.substring( textEnd );
+ text = html.substring(0, textEnd);
+ html = html.substring(textEnd);
}
else {
text = html;
nextTag = nextTagMatch.tagName;
}
else {
- nextTagMatch = html.match( endTag );
+ nextTagMatch = html.match(endTag);
if (nextTagMatch) {
nextTag = '/' + nextTagMatch[1];
}
}
}
- if ( handler.chars ) {
+ if (handler.chars) {
handler.chars(text, prevTag, nextTag);
}
prevTag = '';
.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1');
}
- if ( handler.chars ) {
- handler.chars( text );
+ if (handler.chars) {
+ handler.chars(text);
}
return '';
});
- parseEndTag( '</' + stackedTag + '>', stackedTag );
+ parseEndTag('</' + stackedTag + '>', stackedTag);
}
- if ( html === last ) {
+ if (html === last) {
throw new Error('Parse Error: ' + html);
}
}
var unarySlash = match.unarySlash;
if (handler.html5 && lastTag === 'p' && nonPhrasing(tagName)) {
- parseEndTag( '', lastTag );
+ parseEndTag('', lastTag);
}
if (!handler.html5) {
while (lastTag && inline(lastTag)) {
- parseEndTag( '', lastTag );
+ parseEndTag('', lastTag);
}
}
- if ( closeSelf(tagName) && lastTag === tagName ) {
- parseEndTag( '', tagName );
+ if (closeSelf(tagName) && lastTag === tagName) {
+ parseEndTag('', tagName);
}
var unary = empty(tagName) || tagName === 'html' && lastTag === 'head' || !!unarySlash;
};
});
- if ( !unary ) {
- stack.push( { tag: tagName, attrs: attrs } );
+ if (!unary) {
+ stack.push({ tag: tagName, attrs: attrs });
lastTag = tagName;
unarySlash = '';
}
- if ( handler.start ) {
- handler.start( tagName, attrs, unary, unarySlash );
+ if (handler.start) {
+ handler.start(tagName, attrs, unary, unarySlash);
}
}
- function parseEndTag( tag, tagName ) {
+ function parseEndTag(tag, tagName) {
var pos;
// If no tag name is provided, clean shop
- if ( !tagName ) {
+ if (!tagName) {
pos = 0;
}
else {
// Find the closest opened tag of the same type
var needle = tagName.toLowerCase();
- for ( pos = stack.length - 1; pos >= 0; pos-- ) {
- if ( stack[ pos ].tag.toLowerCase() === needle ) {
+ for (pos = stack.length - 1; pos >= 0; pos--) {
+ if (stack[pos].tag.toLowerCase() === needle) {
break;
}
}
}
- if ( pos >= 0 ) {
+ if (pos >= 0) {
// Close all the open elements, up the stack
- for ( var i = stack.length - 1; i >= pos; i-- ) {
- if ( handler.end ) {
- handler.end( stack[ i ].tag, stack[ i ].attrs, i > pos || !tag );
+ for (var i = stack.length - 1; i >= pos; i--) {
+ if (handler.end) {
+ handler.end(stack[ i ].tag, stack[ i ].attrs, i > pos || !tag);
}
}
}
exports.HTMLParser = HTMLParser;
-exports.HTMLtoXML = function( html ) {
+exports.HTMLtoXML = function(html) {
var results = '';
new HTMLParser(html, {
- start: function( tag, attrs, unary ) {
+ start: function(tag, attrs, unary) {
results += '<' + tag;
- for ( var i = 0; i < attrs.length; i++ ) {
+ for (var i = 0; i < attrs.length; i++) {
results += ' ' + attrs[i].name + '="' + (attrs[i].value || '').replace(/"/g, '"') + '"';
}
results += (unary ? '/' : '') + '>';
},
- end: function( tag ) {
+ end: function(tag) {
results += '</' + tag + '>';
},
- chars: function( text ) {
+ chars: function(text) {
results += text;
},
- comment: function( text ) {
+ comment: function(text) {
results += '<!--' + text + '-->';
},
ignore: function(text) {
return results;
};
-exports.HTMLtoDOM = function( html, doc ) {
+exports.HTMLtoDOM = function(html, doc) {
// There can be only one of these elements
var one = {
html: true,
base: 'head'
};
- if ( !doc ) {
- if ( typeof DOMDocument !== 'undefined' ) {
+ if (!doc) {
+ if (typeof DOMDocument !== 'undefined') {
doc = new DOMDocument();
}
- else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) {
+ else if (typeof document !== 'undefined' && document.implementation && document.implementation.createDocument) {
doc = document.implementation.createDocument('', '', null);
}
- else if ( typeof ActiveX !== 'undefined' ) {
+ else if (typeof ActiveX !== 'undefined') {
doc = new ActiveXObject('Msxml.DOMDocument');
}
// If we're dealing with an empty document then we
// need to pre-populate it with the HTML document structure
- if ( !documentElement && doc.createElement ) {
+ if (!documentElement && doc.createElement) {
(function() {
var html = doc.createElement('html');
var head = doc.createElement('head');
- head.appendChild( doc.createElement('title') );
- html.appendChild( head );
- html.appendChild( doc.createElement('body') );
- doc.appendChild( html );
+ head.appendChild(doc.createElement('title'));
+ html.appendChild(head);
+ html.appendChild(doc.createElement('body'));
+ doc.appendChild(html);
})();
}
// Find all the unique elements
- if ( doc.getElementsByTagName ) {
- for ( var i in one ) {
- one[ i ] = doc.getElementsByTagName( i )[0];
+ if (doc.getElementsByTagName) {
+ for (var i in one) {
+ one[i] = doc.getElementsByTagName(i)[0];
}
}
// the body element
var curParentNode = one.body;
- new HTMLParser( html, {
- start: function( tagName, attrs, unary ) {
+ new HTMLParser(html, {
+ start: function(tagName, attrs, unary) {
// If it's a pre-built element, then we can ignore
// its construction
- if ( one[ tagName ] ) {
- curParentNode = one[ tagName ];
+ if (one[tagName]) {
+ curParentNode = one[tagName];
return;
}
- var elem = doc.createElement( tagName );
+ var elem = doc.createElement(tagName);
- for ( var attr in attrs ) {
- elem.setAttribute( attrs[ attr ].name, attrs[ attr ].value );
+ for (var attr in attrs) {
+ elem.setAttribute(attrs[attr].name, attrs[attr].value);
}
- if ( structure[ tagName ] && typeof one[ structure[ tagName ] ] !== 'boolean' ) {
- one[ structure[ tagName ] ].appendChild( elem );
+ if (structure[tagName] && typeof one[structure[tagName]] !== 'boolean') {
+ one[structure[tagName]].appendChild(elem);
}
- else if ( curParentNode && curParentNode.appendChild ) {
- curParentNode.appendChild( elem );
+ else if (curParentNode && curParentNode.appendChild) {
+ curParentNode.appendChild(elem);
}
- if ( !unary ) {
- elems.push( elem );
+ if (!unary) {
+ elems.push(elem);
curParentNode = elem;
}
},
- end: function( /* tag */ ) {
+ end: function(/* tag */) {
elems.length -= 1;
// Init the new parentNode
curParentNode = elems[ elems.length - 1 ];
},
- chars: function( text ) {
- curParentNode.appendChild( doc.createTextNode( text ) );
+ chars: function(text) {
+ curParentNode.appendChild(doc.createTextNode(text));
},
- comment: function( /* text */ ) {
+ comment: function(/* text */) {
// create comment node
},
- ignore: function( /* text */ ) {
+ ignore: function(/* text */) {
// What to do here?
}
});
var parts = [ ];
var token, isLast = true;
- for (var i = attrs.length; --i >= 0; ) {
+ for (var i = attrs.length; --i >= 0;) {
if (lint) {
lint.testAttribute(tag, attrs[i].name.toLowerCase(), attrs[i].value);
}
var parts = [ ];
var token, isLast = true;
- for (var i = attrs.length; --i >= 0; ) {
+ for (var i = attrs.length; --i >= 0;) {
if (lint) {
lint.testAttribute(tag, attrs[i].name.toLowerCase(), attrs[i].value);
}
+ '\\s*(?:' + singleAttrValues.join('|') + '))?';
if (handler.customAttrSurround) {
var attrClauses = [];
- for ( var i = handler.customAttrSurround.length - 1; i >= 0; i-- ) {
+ for (var i = handler.customAttrSurround.length - 1; i >= 0; i--) {
attrClauses[i] = '(?:'
+ '(' + handler.customAttrSurround[i][0].source + ')\\s*'
+ pattern
return new RegExp('^\\s*' + pattern);
}
-function joinSingleAttrAssigns( handler ) {
+function joinSingleAttrAssigns(handler) {
return singleAttrAssigns.concat(
handler.customAttrAssign || []
).map(function (assign) {
}).join('|');
}
-function HTMLParser( html, handler ) {
+function HTMLParser(html, handler) {
var stack = [], lastTag;
var attribute = attrForHandler(handler);
var last, prevTag, nextTag;
- while ( html ) {
+ while (html) {
last = html;
// Make sure we're not in a script or style element
- if ( !lastTag || !special(lastTag) ) {
+ if (!lastTag || !special(lastTag)) {
var textEnd = html.indexOf('<');
if (textEnd === 0) {
// Comment:
- if ( /^<!--/.test( html ) ) {
+ if (/^<!--/.test(html)) {
var commentEnd = html.indexOf('-->');
- if ( commentEnd >= 0 ) {
- if ( handler.comment ) {
- handler.comment( html.substring( 4, commentEnd ) );
+ if (commentEnd >= 0) {
+ if (handler.comment) {
+ handler.comment(html.substring(4, commentEnd));
}
- html = html.substring( commentEnd + 3 );
+ html = html.substring(commentEnd + 3);
prevTag = '';
continue;
}
}
// http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment
- if ( /^<!\[/.test( html ) ) {
+ if (/^<!\[/.test(html)) {
var conditionalEnd = html.indexOf(']>');
if (conditionalEnd >= 0) {
- if ( handler.comment ) {
- handler.comment( html.substring(2, conditionalEnd + 1 ), true /* non-standard */ );
+ if (handler.comment) {
+ handler.comment(html.substring(2, conditionalEnd + 1), true /* non-standard */);
}
- html = html.substring( conditionalEnd + 2 );
+ html = html.substring(conditionalEnd + 2);
prevTag = '';
continue;
}
}
// Doctype:
- var doctypeMatch = html.match( doctype );
- if ( doctypeMatch ) {
- if ( handler.doctype ) {
- handler.doctype( doctypeMatch[0] );
+ var doctypeMatch = html.match(doctype);
+ if (doctypeMatch) {
+ if (handler.doctype) {
+ handler.doctype(doctypeMatch[0]);
}
- html = html.substring( doctypeMatch[0].length );
+ html = html.substring(doctypeMatch[0].length);
prevTag = '';
continue;
}
// End tag:
- var endTagMatch = html.match( endTag );
- if ( endTagMatch ) {
- html = html.substring( endTagMatch[0].length );
- endTagMatch[0].replace( endTag, parseEndTag );
+ var endTagMatch = html.match(endTag);
+ if (endTagMatch) {
+ html = html.substring(endTagMatch[0].length);
+ endTagMatch[0].replace(endTag, parseEndTag);
prevTag = '/' + endTagMatch[1].toLowerCase();
continue;
}
// Start tag:
var startTagMatch = parseStartTag(html);
- if ( startTagMatch ) {
+ if (startTagMatch) {
html = startTagMatch.rest;
handleStartTag(startTagMatch);
prevTag = startTagMatch.tagName.toLowerCase();
var text;
if (textEnd >= 0) {
- text = html.substring( 0, textEnd );
- html = html.substring( textEnd );
+ text = html.substring(0, textEnd);
+ html = html.substring(textEnd);
}
else {
text = html;
nextTag = nextTagMatch.tagName;
}
else {
- nextTagMatch = html.match( endTag );
+ nextTagMatch = html.match(endTag);
if (nextTagMatch) {
nextTag = '/' + nextTagMatch[1];
}
}
}
- if ( handler.chars ) {
+ if (handler.chars) {
handler.chars(text, prevTag, nextTag);
}
prevTag = '';
.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1');
}
- if ( handler.chars ) {
- handler.chars( text );
+ if (handler.chars) {
+ handler.chars(text);
}
return '';
});
- parseEndTag( '</' + stackedTag + '>', stackedTag );
+ parseEndTag('</' + stackedTag + '>', stackedTag);
}
- if ( html === last ) {
+ if (html === last) {
throw new Error('Parse Error: ' + html);
}
}
var unarySlash = match.unarySlash;
if (handler.html5 && lastTag === 'p' && nonPhrasing(tagName)) {
- parseEndTag( '', lastTag );
+ parseEndTag('', lastTag);
}
if (!handler.html5) {
while (lastTag && inline(lastTag)) {
- parseEndTag( '', lastTag );
+ parseEndTag('', lastTag);
}
}
- if ( closeSelf(tagName) && lastTag === tagName ) {
- parseEndTag( '', tagName );
+ if (closeSelf(tagName) && lastTag === tagName) {
+ parseEndTag('', tagName);
}
var unary = empty(tagName) || tagName === 'html' && lastTag === 'head' || !!unarySlash;
};
});
- if ( !unary ) {
- stack.push( { tag: tagName, attrs: attrs } );
+ if (!unary) {
+ stack.push({ tag: tagName, attrs: attrs });
lastTag = tagName;
unarySlash = '';
}
- if ( handler.start ) {
- handler.start( tagName, attrs, unary, unarySlash );
+ if (handler.start) {
+ handler.start(tagName, attrs, unary, unarySlash);
}
}
- function parseEndTag( tag, tagName ) {
+ function parseEndTag(tag, tagName) {
var pos;
// If no tag name is provided, clean shop
- if ( !tagName ) {
+ if (!tagName) {
pos = 0;
}
else {
// Find the closest opened tag of the same type
var needle = tagName.toLowerCase();
- for ( pos = stack.length - 1; pos >= 0; pos-- ) {
- if ( stack[ pos ].tag.toLowerCase() === needle ) {
+ for (pos = stack.length - 1; pos >= 0; pos--) {
+ if (stack[pos].tag.toLowerCase() === needle) {
break;
}
}
}
- if ( pos >= 0 ) {
+ if (pos >= 0) {
// Close all the open elements, up the stack
- for ( var i = stack.length - 1; i >= pos; i-- ) {
- if ( handler.end ) {
- handler.end( stack[ i ].tag, stack[ i ].attrs, i > pos || !tag );
+ for (var i = stack.length - 1; i >= pos; i--) {
+ if (handler.end) {
+ handler.end(stack[ i ].tag, stack[ i ].attrs, i > pos || !tag);
}
}
}
exports.HTMLParser = HTMLParser;
-exports.HTMLtoXML = function( html ) {
+exports.HTMLtoXML = function(html) {
var results = '';
new HTMLParser(html, {
- start: function( tag, attrs, unary ) {
+ start: function(tag, attrs, unary) {
results += '<' + tag;
- for ( var i = 0; i < attrs.length; i++ ) {
+ for (var i = 0; i < attrs.length; i++) {
results += ' ' + attrs[i].name + '="' + (attrs[i].value || '').replace(/"/g, '"') + '"';
}
results += (unary ? '/' : '') + '>';
},
- end: function( tag ) {
+ end: function(tag) {
results += '</' + tag + '>';
},
- chars: function( text ) {
+ chars: function(text) {
results += text;
},
- comment: function( text ) {
+ comment: function(text) {
results += '<!--' + text + '-->';
},
ignore: function(text) {
return results;
};
-exports.HTMLtoDOM = function( html, doc ) {
+exports.HTMLtoDOM = function(html, doc) {
// There can be only one of these elements
var one = {
html: true,
base: 'head'
};
- if ( !doc ) {
- if ( typeof DOMDocument !== 'undefined' ) {
+ if (!doc) {
+ if (typeof DOMDocument !== 'undefined') {
doc = new DOMDocument();
}
- else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) {
+ else if (typeof document !== 'undefined' && document.implementation && document.implementation.createDocument) {
doc = document.implementation.createDocument('', '', null);
}
- else if ( typeof ActiveX !== 'undefined' ) {
+ else if (typeof ActiveX !== 'undefined') {
doc = new ActiveXObject('Msxml.DOMDocument');
}
// If we're dealing with an empty document then we
// need to pre-populate it with the HTML document structure
- if ( !documentElement && doc.createElement ) {
+ if (!documentElement && doc.createElement) {
(function() {
var html = doc.createElement('html');
var head = doc.createElement('head');
- head.appendChild( doc.createElement('title') );
- html.appendChild( head );
- html.appendChild( doc.createElement('body') );
- doc.appendChild( html );
+ head.appendChild(doc.createElement('title'));
+ html.appendChild(head);
+ html.appendChild(doc.createElement('body'));
+ doc.appendChild(html);
})();
}
// Find all the unique elements
- if ( doc.getElementsByTagName ) {
- for ( var i in one ) {
- one[ i ] = doc.getElementsByTagName( i )[0];
+ if (doc.getElementsByTagName) {
+ for (var i in one) {
+ one[i] = doc.getElementsByTagName(i)[0];
}
}
// the body element
var curParentNode = one.body;
- new HTMLParser( html, {
- start: function( tagName, attrs, unary ) {
+ new HTMLParser(html, {
+ start: function(tagName, attrs, unary) {
// If it's a pre-built element, then we can ignore
// its construction
- if ( one[ tagName ] ) {
- curParentNode = one[ tagName ];
+ if (one[tagName]) {
+ curParentNode = one[tagName];
return;
}
- var elem = doc.createElement( tagName );
+ var elem = doc.createElement(tagName);
- for ( var attr in attrs ) {
- elem.setAttribute( attrs[ attr ].name, attrs[ attr ].value );
+ for (var attr in attrs) {
+ elem.setAttribute(attrs[attr].name, attrs[attr].value);
}
- if ( structure[ tagName ] && typeof one[ structure[ tagName ] ] !== 'boolean' ) {
- one[ structure[ tagName ] ].appendChild( elem );
+ if (structure[tagName] && typeof one[structure[tagName]] !== 'boolean') {
+ one[structure[tagName]].appendChild(elem);
}
- else if ( curParentNode && curParentNode.appendChild ) {
- curParentNode.appendChild( elem );
+ else if (curParentNode && curParentNode.appendChild) {
+ curParentNode.appendChild(elem);
}
- if ( !unary ) {
- elems.push( elem );
+ if (!unary) {
+ elems.push(elem);
curParentNode = elem;
}
},
- end: function( /* tag */ ) {
+ end: function(/* tag */) {
elems.length -= 1;
// Init the new parentNode
curParentNode = elems[ elems.length - 1 ];
},
- chars: function( text ) {
- curParentNode.appendChild( doc.createTextNode( text ) );
+ chars: function(text) {
+ curParentNode.appendChild(doc.createTextNode(text));
},
- comment: function( /* text */ ) {
+ comment: function(/* text */) {
// create comment node
},
- ignore: function( /* text */ ) {
+ ignore: function(/* text */) {
// What to do here?
}
});
input = '<div ng-some\n\n></div>';
output = '<div ng-some></div>';
- equal(minify( input, { customAttrCollapse: /.+/ }), output);
+ equal(minify(input, { customAttrCollapse: /.+/ }), output);
});
test('custom attribute collapse with newlines, whitespace, and carriage returns', function() {