aboutsummaryrefslogtreecommitdiff
path: root/lib/html
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-10-13 21:24:38 +0100
committerMichael Williamson <mike@zwobble.org>2015-10-13 21:24:38 +0100
commit5f67ade998b13797f95ad6ccc2749b7697c8a661 (patch)
tree3188a5a60c2e94ec80d236006a9f70411e85e256 /lib/html
parent4163a1ec773f0695baa41000050745df37f789e0 (diff)
Add HTML text and fragment nodes
Diffstat (limited to 'lib/html')
-rw-r--r--lib/html/ast.js24
-rw-r--r--lib/html/index.js4
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/html/ast.js b/lib/html/ast.js
new file mode 100644
index 0000000..f5f38da
--- /dev/null
+++ b/lib/html/ast.js
@@ -0,0 +1,24 @@
+var _ = require("underscore");
+
+function fragment(children) {
+ return {
+ type: "fragment",
+ children: collapseFragments(children || [])
+ };
+}
+
+function text(value) {
+ return {
+ type: "text",
+ value: value
+ };
+}
+
+function collapseFragments(elements) {
+ return _.flatten(elements.map(function(element) {
+ return element.type === "fragment" ? element.children : [element];
+ }), true)
+}
+
+exports.fragment = fragment;
+exports.text = text;
diff --git a/lib/html/index.js b/lib/html/index.js
new file mode 100644
index 0000000..5e28f7b
--- /dev/null
+++ b/lib/html/index.js
@@ -0,0 +1,4 @@
+var ast = require("./ast.js");
+
+exports.fragment = ast.fragment;
+exports.text = ast.text;