aboutsummaryrefslogtreecommitdiff
path: root/lib/html/ast.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/html/ast.js')
-rw-r--r--lib/html/ast.js31
1 files changed, 28 insertions, 3 deletions
diff --git a/lib/html/ast.js b/lib/html/ast.js
index afecfce..96aa6c6 100644
--- a/lib/html/ast.js
+++ b/lib/html/ast.js
@@ -20,24 +20,49 @@ function elementWithTag(tag, children) {
return {
type: "element",
tag: tag,
- children: collapseFragments(children)
+ children: collapseFragments(children),
+ isEmpty: _.all(children, function(child) {
+ return child.isEmpty;
+ }),
+ appendChild: appendChild
+ };
+}
+
+function appendChild(child) {
+ this.children.push(child);
+ this.isEmpty = this.isEmpty && child.isEmpty;
+}
+
+function selfClosingElement(tagName, attributes) {
+ return {
+ type: "selfClosingElement",
+ tagName: tagName,
+ attributes: attributes
};
}
function text(value) {
return {
type: "text",
- value: value
+ value: value,
+ isEmpty: !value
};
}
+var forceWrite = {
+ type: "forceWrite",
+ isEmpty: false
+};
+
function collapseFragments(elements) {
return _.flatten((elements || []).map(function(element) {
return element.type === "fragment" ? element.children : [element];
- }), true)
+ }), true);
}
exports.fragment = fragment;
exports.element = element;
exports.elementWithTag = elementWithTag;
+exports.selfClosingElement = selfClosingElement;
exports.text = text;
+exports.forceWrite = forceWrite;