Commit 329c15f2 authored by jan.koester's avatar jan.koester
Browse files

test

parent e071bfb8
Loading
Loading
Loading
Loading
+43 −9
Changes for src/edit.cpp: 43 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -567,22 +567,56 @@ std::string blogi::webedit::WebEditor::extractCustomCss(

std::string blogi::webedit::WebEditor::serializeElement(const libhtmlpp::Element *el) {
    if (!el) return "";
    libhtmlpp::HtmlString out;
    libhtmlpp::print(*el, out);
    return out.str();
    if (el->getType() == libhtmlpp::HtmlEl || el->getType() == libhtmlpp::SvgEL ||
        el->getType() == libhtmlpp::TextAreaEL) {
        const libhtmlpp::HtmlElement *hel = static_cast<const libhtmlpp::HtmlElement*>(el);
        std::string tag = hel->getTagname();
        std::string result = "<" + tag;
        // Iterate all attributes using the public API
        for (const auto *attr = hel->firstAttribute(); attr; attr = attr->nextAttribute()) {
            result += " " + attr->getKey();
            std::string val = attr->getValue();
            if (!val.empty()) {
                result += "=\"" + val + "\"";
            }
        }
        result += ">";
        result += serializeInnerHtml(const_cast<libhtmlpp::HtmlElement*>(hel));
        result += "</" + tag + ">";
        return result;
    } else if (el->getType() == libhtmlpp::TextEl) {
        return const_cast<libhtmlpp::TextElement*>(static_cast<const libhtmlpp::TextElement*>(el))->getText();
    } else if (el->getType() == libhtmlpp::ScriptEL) {
        const libhtmlpp::ScriptElement *sel = static_cast<const libhtmlpp::ScriptElement*>(el);
        std::string tag = sel->getTagname();
        std::string result = "<" + tag;
        for (const auto *attr = sel->firstAttribute(); attr; attr = attr->nextAttribute()) {
            result += " " + attr->getKey();
            std::string val = attr->getValue();
            if (!val.empty()) {
                result += "=\"" + val + "\"";
            }
        }
        result += ">";
        result += const_cast<libhtmlpp::ScriptElement*>(sel)->getScript();
        result += "</" + tag + ">";
        return result;
    } else if (el->getType() == libhtmlpp::CommentEl) {
        return "<!--" + const_cast<libhtmlpp::CommentElement*>(
            static_cast<const libhtmlpp::CommentElement*>(el))->getComment() + "-->";
    }
    return "";
}

std::string blogi::webedit::WebEditor::serializeInnerHtml(libhtmlpp::HtmlElement *el) {
    if (!el) return "";
    std::string result;
    libhtmlpp::Element *child = el->firstChild();
    while (child) {
    if (!child) return "";
    // print() serializes the element AND all its siblings,
    // so calling it once on firstChild gives all children
    libhtmlpp::HtmlString out;
    libhtmlpp::print(*child, out);
        result += out.str();
        child = child->nextElement();
    }
    return result;
    return out.str();
}

void blogi::webedit::WebEditor::htmlElementToWidgetXml(