aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-10-13 21:26:50 +0100
committerMichael Williamson <mike@zwobble.org>2015-10-13 21:26:50 +0100
commit2fb7a36230b167aac99fe8d43959833bd3b244dd (patch)
tree18409fc8a2f843e64774e3c32e89e0d5aa32281c /lib
parent5f67ade998b13797f95ad6ccc2749b7697c8a661 (diff)
Add element node
Diffstat (limited to 'lib')
-rw-r--r--lib/html/ast.js14
-rw-r--r--lib/html/index.js1
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/html/ast.js b/lib/html/ast.js
index f5f38da..25f4874 100644
--- a/lib/html/ast.js
+++ b/lib/html/ast.js
@@ -3,7 +3,16 @@ var _ = require("underscore");
function fragment(children) {
return {
type: "fragment",
- children: collapseFragments(children || [])
+ children: collapseFragments(children)
+ };
+}
+
+function element(tagName, attributes, children) {
+ return {
+ type: "element",
+ tagName: tagName,
+ attributes: attributes,
+ children: collapseFragments(children)
};
}
@@ -15,10 +24,11 @@ function text(value) {
}
function collapseFragments(elements) {
- return _.flatten(elements.map(function(element) {
+ return _.flatten((elements || []).map(function(element) {
return element.type === "fragment" ? element.children : [element];
}), true)
}
exports.fragment = fragment;
+exports.element = element;
exports.text = text;
diff --git a/lib/html/index.js b/lib/html/index.js
index 5e28f7b..f9e957a 100644
--- a/lib/html/index.js
+++ b/lib/html/index.js
@@ -1,4 +1,5 @@
var ast = require("./ast.js");
exports.fragment = ast.fragment;
+exports.element = ast.element;
exports.text = ast.text;