html-parse-stringify2
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -1,2 +0,2 @@ | ||
var attrRE = /([\w-]+)|(['"])([.\s\S]*?)\2/g; | ||
var attrRE = /([\w-]+)|=|(['"])([.\s\S]*?)\2/g; | ||
var voidElements = require('void-elements'); | ||
@@ -7,2 +7,3 @@ | ||
var key; | ||
var expectingValueAfterEquals = true; | ||
var res = { | ||
@@ -17,4 +18,13 @@ type: 'tag', | ||
tag.replace(attrRE, function (match) { | ||
if (i % 2) { | ||
key = match; | ||
if (match === '=') { | ||
expectingValueAfterEquals = true; | ||
i++; | ||
return; | ||
} | ||
if (!expectingValueAfterEquals) { | ||
if (key) { | ||
res.attrs[key] = key; // boolean attribute | ||
} | ||
key=match; | ||
} else { | ||
@@ -28,5 +38,7 @@ if (i === 0) { | ||
res.attrs[key] = match.replace(/^['"]|['"]$/g, ''); | ||
key=undefined; | ||
} | ||
} | ||
i++; | ||
expectingValueAfterEquals = false; | ||
}); | ||
@@ -33,0 +45,0 @@ |
{ | ||
"name": "html-parse-stringify2", | ||
"description": "Parses well-formed HTML (meaning all tags closed) into an AST and back. quickly.", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"author": "Ray Di Ciaccio <ray.diciaccio@gmail.com>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -69,3 +69,3 @@ var test = require('tape'); | ||
}); | ||
tag = '<textarea placeholder=\'Hey Usher, \n\nAre these modals for real?!\' class=\'placeholder-value\'>'; | ||
@@ -84,3 +84,17 @@ | ||
tag = '<input checked name="sad" type="checkbox">'; | ||
t.deepEqual(parseTag(tag), { | ||
type: 'tag', | ||
attrs: { | ||
type: 'checkbox', | ||
checked: 'checked', | ||
name: 'sad' | ||
}, | ||
name: 'input', | ||
voidElement: true, | ||
children: [] | ||
}); | ||
t.end(); | ||
}); |
31138
740