From 0ad3a12213086e433c617fb951edaada6e7500f5 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 10 Dec 2016 21:53:24 +0000 Subject: Remove self-closing tags from AST --- lib/html/ast.js | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'lib/html/ast.js') 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; -- cgit v1.2.3