@unisnips/jetbrains
Version:
Utilities for generating JetBrains live templates in unisnips project
51 lines • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function indent(str, cols) {
var prefix = '';
for (var i = 0; i < cols; i++) {
prefix += ' ';
}
return str
.split('\n')
.map(function (l) {
return prefix + l;
})
.join('\n');
}
exports.indent = indent;
function nodeTreeToXml(root, level) {
if (level === void 0) { level = 0; }
var attrStr = root.attributes
.filter(function (attr) { return attr.value !== undefined; })
.map(function (attr) {
return attr.name + "=\"" + attr.value.toString() + "\"";
})
.join(' ');
var childrenStr = root.children
? root.children
.map(function (child) {
return nodeTreeToXml(child, 1);
})
.join('\n')
: '';
if (childrenStr) {
return indent("<" + root.tagName + " " + attrStr + ">\n" + childrenStr + "\n</" + root.tagName + ">", level * 2);
}
else {
return indent("<" + root.tagName + " " + attrStr + " />", level * 2);
}
}
exports.nodeTreeToXml = nodeTreeToXml;
function attr(name, value) {
return { name: name, value: value };
}
exports.attr = attr;
function makeTag(name, attrs, children) {
return {
tagName: name,
attributes: attrs,
children: children,
};
}
exports.makeTag = makeTag;
//# sourceMappingURL=xml.js.map