blob: 25f48743730c38b9ce7dbd53e8633dd4ef66d162 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
var _ = require("underscore");
function fragment(children) {
return {
type: "fragment",
children: collapseFragments(children)
};
}
function element(tagName, attributes, children) {
return {
type: "element",
tagName: tagName,
attributes: attributes,
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.element = element;
exports.text = text;
|