diff options
Diffstat (limited to 'lib/html/ast.js')
| -rw-r--r-- | lib/html/ast.js | 24 |
1 files changed, 24 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; |
