aboutsummaryrefslogtreecommitdiff
path: root/lib/html/ast.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-11-28 17:48:31 +0000
committerMichael Williamson <mike@zwobble.org>2016-11-28 17:48:31 +0000
commit611e0c9af7c1948ad46c5471a426ec751e73a1ea (patch)
tree28954bd7f66bd306345f36eebca20df1bd1b07ee /lib/html/ast.js
parent5428d4daeebd8d1fa8a67b20e2f8a238d3b0abbf (diff)
Call freshElement to create self-closing elements
Diffstat (limited to 'lib/html/ast.js')
-rw-r--r--lib/html/ast.js20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/html/ast.js b/lib/html/ast.js
index 0dd8120..c949550 100644
--- a/lib/html/ast.js
+++ b/lib/html/ast.js
@@ -8,9 +8,22 @@ function nonFreshElement(tagName, attributes, children) {
}
function freshElement(tagName, attributes, children) {
- return elementWithTag(
- htmlPaths.element(tagName, attributes, {fresh: true}),
- children);
+ if (isVoidElement(tagName, children)) {
+ return selfClosingElement(tagName, attributes);
+ } else {
+ var tag = htmlPaths.element(tagName, attributes, {fresh: true});
+ return elementWithTag(tag, children);
+ }
+}
+
+var voidTagNames = {
+ "br": true,
+ "hr": true,
+ "img": true
+};
+
+function isVoidElement(tagName, children) {
+ return (!children || children.length === 0) && voidTagNames[tagName];
}
function elementWithTag(tag, children) {
@@ -43,6 +56,5 @@ var forceWrite = {
exports.freshElement = freshElement;
exports.nonFreshElement = nonFreshElement;
exports.elementWithTag = elementWithTag;
-exports.selfClosingElement = selfClosingElement;
exports.text = text;
exports.forceWrite = forceWrite;