Loading src/edit.cpp +36 −23 Changes for src/edit.cpp: 36 added lines, 23 removed lines. Original line number Diff line number Diff line Loading @@ -627,19 +627,32 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( { if (!htmlEl) return; libhtmlpp::Element *cur = htmlEl; // Iterative traversal using an explicit heap-allocated stack to avoid // thread stack overflow (musl default thread stack is only 128KB). struct Frame { libhtmlpp::Element *cur; tinyxml2::XMLElement *pXml; }; std::stack<Frame> workStack; workStack.push({htmlEl, parentXml}); while (!workStack.empty()) { auto frame = workStack.top(); workStack.pop(); // Collect child frames to push later (in reverse for document order) std::vector<Frame> childFrames; libhtmlpp::Element *cur = frame.cur; tinyxml2::XMLElement *pXml = frame.pXml; while (cur) { int type = cur->getType(); if (type == libhtmlpp::TextEl) { // Text node libhtmlpp::TextElement *textEl = static_cast<libhtmlpp::TextElement*>(cur); std::string text = textEl->getText(); if (text.find_first_not_of(" \t\n\r") != std::string::npos) { tinyxml2::XMLElement *tb = doc.NewElement("TextBox"); tb->SetText(text.c_str()); parentXml->InsertEndChild(tb); pXml->InsertEndChild(tb); } cur = cur->nextElement(); continue; Loading @@ -651,7 +664,6 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( } if (type == libhtmlpp::ScriptEL) { // Skip script elements for security cur = cur->nextElement(); continue; } Loading @@ -673,7 +685,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( tag == "aside") { libhtmlpp::Element *child = el->firstChild(); if (child) { htmlElementToWidgetXml(child, doc, parentXml, sheet); childFrames.push_back({child, pXml}); } cur = cur->nextElement(); continue; Loading Loading @@ -711,9 +723,9 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); libhtmlpp::Element *child = el->firstChild(); if (child) htmlElementToWidgetXml(child, doc, w, sheet); if (child) childFrames.push_back({child, w}); } else if (tag == "div") { tinyxml2::XMLElement *w = doc.NewElement("Container"); Loading Loading @@ -750,9 +762,9 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( w->InsertEndChild(ccEl); } } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); libhtmlpp::Element *child = el->firstChild(); if (child) htmlElementToWidgetXml(child, doc, w, sheet); if (child) childFrames.push_back({child, w}); } else if (tag == "img") { tinyxml2::XMLElement *w = doc.NewElement("Image"); Loading @@ -776,7 +788,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "video") { tinyxml2::XMLElement *w = doc.NewElement("Video"); Loading @@ -793,18 +805,16 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "table") { tinyxml2::XMLElement *w = doc.NewElement("Table"); if (cssProps.count("border")) w->SetAttribute("border_style", cssProps["border"].c_str()); if (cssProps.count("background-color")) w->SetAttribute("background_color", cssProps["background-color"].c_str()); // Walk table children to count rows/cols and extract cell data int numRows = 0, numCols = 0; bool hasHeader = false; // Helper lambda to process <tr> elements struct RowData { std::vector<std::string> cells; bool isHeader; }; std::vector<RowData> rows; Loading @@ -830,7 +840,6 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( if (header) hasHeader = true; }; // Walk table children: thead, tbody, or direct tr libhtmlpp::Element *tblChild = el->firstChild(); while (tblChild) { if (tblChild->getType() == libhtmlpp::HtmlEl) { Loading Loading @@ -897,7 +906,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "ul" || tag == "ol") { tinyxml2::XMLElement *w = doc.NewElement("List"); Loading Loading @@ -935,10 +944,9 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "a") { // Check if simple text link → Button, otherwise recurse bool hasChildElements = false; libhtmlpp::Element *aChild = el->firstChild(); while (aChild) { Loading Loading @@ -971,14 +979,13 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else { // Link wrapping child elements → CustomHtml tinyxml2::XMLElement *w = doc.NewElement("CustomHtml"); tinyxml2::XMLElement *htmlContent = doc.NewElement("HtmlContent"); htmlContent->SetText(serializeElement(cur).c_str()); w->InsertEndChild(htmlContent); parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } } else if (tag == "h1" || tag == "h2" || tag == "h3" || tag == "h4" || Loading Loading @@ -1010,7 +1017,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "style") { // Already collected during preprocessing — skip Loading @@ -1020,7 +1027,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( tinyxml2::XMLElement *htmlContent = doc.NewElement("HtmlContent"); htmlContent->SetText(("<" + tag + ">").c_str()); w->InsertEndChild(htmlContent); parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "meta" || tag == "link" || tag == "title" || tag == "base" || tag == "DOCTYPE" || tag == "!doctype") { Loading @@ -1038,11 +1045,17 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( cssEl->SetText(style.c_str()); w->InsertEndChild(cssEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } cur = cur->nextElement(); } // Push child frames in reverse so they are processed in document order (LIFO) for (auto it = childFrames.rbegin(); it != childFrames.rend(); ++it) { workStack.push(*it); } } } void blogi::webedit::WebEditor::importHtmlToWidgets(const std::string &html) { Loading Loading
src/edit.cpp +36 −23 Changes for src/edit.cpp: 36 added lines, 23 removed lines. Original line number Diff line number Diff line Loading @@ -627,19 +627,32 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( { if (!htmlEl) return; libhtmlpp::Element *cur = htmlEl; // Iterative traversal using an explicit heap-allocated stack to avoid // thread stack overflow (musl default thread stack is only 128KB). struct Frame { libhtmlpp::Element *cur; tinyxml2::XMLElement *pXml; }; std::stack<Frame> workStack; workStack.push({htmlEl, parentXml}); while (!workStack.empty()) { auto frame = workStack.top(); workStack.pop(); // Collect child frames to push later (in reverse for document order) std::vector<Frame> childFrames; libhtmlpp::Element *cur = frame.cur; tinyxml2::XMLElement *pXml = frame.pXml; while (cur) { int type = cur->getType(); if (type == libhtmlpp::TextEl) { // Text node libhtmlpp::TextElement *textEl = static_cast<libhtmlpp::TextElement*>(cur); std::string text = textEl->getText(); if (text.find_first_not_of(" \t\n\r") != std::string::npos) { tinyxml2::XMLElement *tb = doc.NewElement("TextBox"); tb->SetText(text.c_str()); parentXml->InsertEndChild(tb); pXml->InsertEndChild(tb); } cur = cur->nextElement(); continue; Loading @@ -651,7 +664,6 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( } if (type == libhtmlpp::ScriptEL) { // Skip script elements for security cur = cur->nextElement(); continue; } Loading @@ -673,7 +685,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( tag == "aside") { libhtmlpp::Element *child = el->firstChild(); if (child) { htmlElementToWidgetXml(child, doc, parentXml, sheet); childFrames.push_back({child, pXml}); } cur = cur->nextElement(); continue; Loading Loading @@ -711,9 +723,9 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); libhtmlpp::Element *child = el->firstChild(); if (child) htmlElementToWidgetXml(child, doc, w, sheet); if (child) childFrames.push_back({child, w}); } else if (tag == "div") { tinyxml2::XMLElement *w = doc.NewElement("Container"); Loading Loading @@ -750,9 +762,9 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( w->InsertEndChild(ccEl); } } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); libhtmlpp::Element *child = el->firstChild(); if (child) htmlElementToWidgetXml(child, doc, w, sheet); if (child) childFrames.push_back({child, w}); } else if (tag == "img") { tinyxml2::XMLElement *w = doc.NewElement("Image"); Loading @@ -776,7 +788,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "video") { tinyxml2::XMLElement *w = doc.NewElement("Video"); Loading @@ -793,18 +805,16 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "table") { tinyxml2::XMLElement *w = doc.NewElement("Table"); if (cssProps.count("border")) w->SetAttribute("border_style", cssProps["border"].c_str()); if (cssProps.count("background-color")) w->SetAttribute("background_color", cssProps["background-color"].c_str()); // Walk table children to count rows/cols and extract cell data int numRows = 0, numCols = 0; bool hasHeader = false; // Helper lambda to process <tr> elements struct RowData { std::vector<std::string> cells; bool isHeader; }; std::vector<RowData> rows; Loading @@ -830,7 +840,6 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( if (header) hasHeader = true; }; // Walk table children: thead, tbody, or direct tr libhtmlpp::Element *tblChild = el->firstChild(); while (tblChild) { if (tblChild->getType() == libhtmlpp::HtmlEl) { Loading Loading @@ -897,7 +906,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "ul" || tag == "ol") { tinyxml2::XMLElement *w = doc.NewElement("List"); Loading Loading @@ -935,10 +944,9 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "a") { // Check if simple text link → Button, otherwise recurse bool hasChildElements = false; libhtmlpp::Element *aChild = el->firstChild(); while (aChild) { Loading Loading @@ -971,14 +979,13 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else { // Link wrapping child elements → CustomHtml tinyxml2::XMLElement *w = doc.NewElement("CustomHtml"); tinyxml2::XMLElement *htmlContent = doc.NewElement("HtmlContent"); htmlContent->SetText(serializeElement(cur).c_str()); w->InsertEndChild(htmlContent); parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } } else if (tag == "h1" || tag == "h2" || tag == "h3" || tag == "h4" || Loading Loading @@ -1010,7 +1017,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( ccEl->SetText(custom.c_str()); w->InsertEndChild(ccEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "style") { // Already collected during preprocessing — skip Loading @@ -1020,7 +1027,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( tinyxml2::XMLElement *htmlContent = doc.NewElement("HtmlContent"); htmlContent->SetText(("<" + tag + ">").c_str()); w->InsertEndChild(htmlContent); parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } else if (tag == "meta" || tag == "link" || tag == "title" || tag == "base" || tag == "DOCTYPE" || tag == "!doctype") { Loading @@ -1038,11 +1045,17 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( cssEl->SetText(style.c_str()); w->InsertEndChild(cssEl); } parentXml->InsertEndChild(w); pXml->InsertEndChild(w); } cur = cur->nextElement(); } // Push child frames in reverse so they are processed in document order (LIFO) for (auto it = childFrames.rbegin(); it != childFrames.rend(); ++it) { workStack.push(*it); } } } void blogi::webedit::WebEditor::importHtmlToWidgets(const std::string &html) { Loading