Comparing version 1.5.0 to 1.5.1
var ElementType = require("domelementtype"), | ||
getOuterHTML = require("dom-serializer"), | ||
isTag = ElementType.isTag; | ||
@@ -10,80 +11,8 @@ | ||
function getInnerHTML(elem){ | ||
return elem.children ? elem.children.map(getOuterHTML).join("") : ""; | ||
function getInnerHTML(elem, opts){ | ||
return elem.children ? elem.children.map(function(elem){ | ||
return getOuterHTML(elem, opts); | ||
}).join("") : ""; | ||
} | ||
//boolean attributes without a value (taken from MatthewMueller/cheerio) | ||
var booleanAttribs = { | ||
__proto__: null, | ||
async: true, | ||
autofocus: true, | ||
autoplay: true, | ||
checked: true, | ||
controls: true, | ||
defer: true, | ||
disabled: true, | ||
hidden: true, | ||
loop: true, | ||
multiple: true, | ||
open: true, | ||
readonly: true, | ||
required: true, | ||
scoped: true, | ||
selected: true | ||
}; | ||
var emptyTags = { | ||
__proto__: null, | ||
area: true, | ||
base: true, | ||
basefont: true, | ||
br: true, | ||
col: true, | ||
frame: true, | ||
hr: true, | ||
img: true, | ||
input: true, | ||
isindex: true, | ||
link: true, | ||
meta: true, | ||
param: true, | ||
embed: true | ||
}; | ||
function getOuterHTML(elem){ | ||
switch(elem.type){ | ||
case ElementType.Text: | ||
return elem.data; | ||
case ElementType.Comment: | ||
return "<!--" + elem.data + "-->"; | ||
case ElementType.Directive: | ||
return "<" + elem.data + ">"; | ||
case ElementType.CDATA: | ||
return "<!CDATA " + getInnerHTML(elem) + "]]>"; | ||
} | ||
var ret = "<" + elem.name; | ||
if("attribs" in elem){ | ||
for(var attr in elem.attribs){ | ||
if(elem.attribs.hasOwnProperty(attr)){ | ||
ret += " " + attr; | ||
var value = elem.attribs[attr]; | ||
if(value == null){ | ||
if( !(attr in booleanAttribs) ){ | ||
ret += "=\"\""; | ||
} | ||
} else { | ||
ret += "=\"" + value + "\""; | ||
} | ||
} | ||
} | ||
} | ||
if (elem.name in emptyTags && elem.children.length === 0) { | ||
return ret + " />"; | ||
} else { | ||
return ret + ">" + getInnerHTML(elem) + "</" + elem.name + ">"; | ||
} | ||
} | ||
function getText(elem){ | ||
@@ -94,2 +23,2 @@ if(Array.isArray(elem)) return elem.map(getText).join(""); | ||
return ""; | ||
} | ||
} |
@@ -19,3 +19,3 @@ var getChildren = exports.getChildren = function(elem){ | ||
exports.hasAttrib = function(elem, name){ | ||
return hasOwnProperty.call(elem.attribs, name); | ||
return !!elem.attribs && hasOwnProperty.call(elem.attribs, name); | ||
}; | ||
@@ -22,0 +22,0 @@ |
{ | ||
"name": "domutils", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "utilities for working with htmlparser2's dom", | ||
@@ -21,2 +21,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"dom-serializer": "0", | ||
"domelementtype": "1" | ||
@@ -23,0 +24,0 @@ }, |
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
16
20288
2
603
+ Addeddom-serializer@0
+ Addeddom-serializer@0.2.2(transitive)
+ Addeddomelementtype@2.3.0(transitive)
+ Addedentities@2.2.0(transitive)