diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-10-13 21:24:38 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-10-13 21:24:38 +0100 |
| commit | 5f67ade998b13797f95ad6ccc2749b7697c8a661 (patch) | |
| tree | 3188a5a60c2e94ec80d236006a9f70411e85e256 /lib/html/ast.js | |
| parent | 4163a1ec773f0695baa41000050745df37f789e0 (diff) | |
Add HTML text and fragment nodes
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; |
