diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-12-10 21:53:24 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-12-10 21:53:24 +0000 |
| commit | 0ad3a12213086e433c617fb951edaada6e7500f5 (patch) | |
| tree | 4770aad36468db9a6c492d9614165739769915d5 /lib/html/ast.js | |
| parent | 72ad04159683e8958ff957695fc9bb224fc376ca (diff) | |
Remove self-closing tags from AST
Diffstat (limited to 'lib/html/ast.js')
| -rw-r--r-- | lib/html/ast.js | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/lib/html/ast.js b/lib/html/ast.js index 34b9a3d..4b9290d 100644 --- a/lib/html/ast.js +++ b/lib/html/ast.js @@ -12,33 +12,11 @@ function freshElement(tagName, attributes, children) { return elementWithTag(tag, children); } -var voidTagNames = { - "br": true, - "hr": true, - "img": true -}; - function elementWithTag(tag, children) { - if (isVoidElement(tag.tagName, children)) { - return selfClosingElement(tag.tagName, tag.attributes); - } else { - return { - type: "element", - tag: tag, - children: children || [] - }; - } -} - -function isVoidElement(tagName, children) { - return (!children || children.length === 0) && voidTagNames[tagName]; -} - -function selfClosingElement(tagName, attributes) { return { - type: "selfClosingElement", - tagName: tagName, - attributes: attributes + type: "element", + tag: tag, + children: children || [] }; } @@ -58,3 +36,15 @@ exports.nonFreshElement = nonFreshElement; exports.elementWithTag = elementWithTag; exports.text = text; exports.forceWrite = forceWrite; + +var voidTagNames = { + "br": true, + "hr": true, + "img": true +}; + +function isVoidElement(node) { + return (node.children.length === 0) && voidTagNames[node.tag.tagName]; +} + +exports.isVoidElement = isVoidElement; |
