Commit 2a088f30 authored by jan.koester's avatar jan.koester
Browse files

test

parent d0db0228
Loading
Loading
Loading
Loading
+0 −43
Changes for editor/htmlimport.cpp: 0 added lines, 43 removed lines.
Original line number Diff line number Diff line
@@ -718,49 +718,6 @@ void blogi::htmlimport::htmlElementToWidgetXml(
    }
}

static std::string sanitizeHtml(const std::string& input) {
    std::string html = input;
    html = std::regex_replace(html, std::regex{"<!DOCTYPE[^>]*>", std::regex_constants::icase}, "");

    std::regex tag_regex{"<(/?)(\\w+)[^>]*>"};
    std::sregex_iterator begin(html.begin(), html.end(), tag_regex);
    std::sregex_iterator end;

    std::vector<std::string> stack;
    std::vector<std::string> void_elements = {"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr", "!doctype"};
    
    for (auto i = begin; i != end; ++i) {
        std::smatch match = *i;
        bool is_closing = match[1].str() == "/";
        std::string tag_name = match[2].str();
        for (auto &c: tag_name) c = std::tolower(c);
        
        bool is_void = false;
        for (const auto& v : void_elements) {
            if (v == tag_name) { is_void = true; break; }
        }
        if (is_void) continue;
        
        if (is_closing) {
            if (!stack.empty() && stack.back() == tag_name) {
                stack.pop_back();
            } else {
                auto it = std::find(stack.rbegin(), stack.rend(), tag_name);
                if(it != stack.rend()) {
                    stack.erase((it+1).base(), stack.end());
                }
            }
        } else {
            stack.push_back(tag_name);
        }
    }
    
    for (auto it = stack.rbegin(); it != stack.rend(); ++it) {
        html += "</" + *it + ">";
    }
    return html;
}

bool blogi::htmlimport::convertHtmlToWidgetXml(const std::string &html,
                                               std::string &outXml,
                                               std::string &outGlobalCss)