"use strict";
var htmlparser = require("htmlparser2");
function parseHTMLStructure(content) {
    var root = { type: "element", children: [], attrs: {}, name: "root" };
    var stack = [];
    var cur = root;
    var parser = new htmlparser.Parser({
        onopentag: function (name, attrs) {
            var el;
            el = {
                type: "element", attrs: attrs,
                children: [],
                name: name
            };
            cur.children.push(el);
            stack.push(cur);
            cur = el;
        },
        ontext: function (text) {
            cur.children.push({
                type: "text",
                content: text,
                children: null
            });
        },
        onclosetag: function () {
            cur = stack.pop();
        }
    }, { decodeEntities: true });
    parser.end(content);
    return root.children;
}
exports.parseHTMLStructure = parseHTMLStructure;
function structureToString(s) {
    if (s.type === "text")
        return s["content"];
    var result = "";
    for (var _i = 0, _a = s["children"] || []; _i < _a.length; _i++) {
        var child = _a[_i];
        result += structureToString(child);
    }
    return result;
}
exports.structureToString = structureToString;
//# sourceMappingURL=htmlStructure.js.map