Loading editor/src/htmlimport.cpp +19 −2 Original line number Diff line number Diff line Loading @@ -1045,6 +1045,12 @@ void blogi::htmlimport::htmlElementToWidgetXml( if (cssProps.count("background-color")) w->SetAttribute("background_color", cssProps["background-color"].c_str()); if (cssProps.count("width")) w->SetAttribute("width", cssProps["width"].c_str()); if (cssProps.count("height")) w->SetAttribute("height", cssProps["height"].c_str()); if (cssMeansHidden(cssProps)) w->SetAttribute("hidden", "true"); int numRows = 0, numCols = 0; bool hasHeader = false; Loading Loading @@ -1144,7 +1150,8 @@ void blogi::htmlimport::htmlElementToWidgetXml( } std::vector<std::string> knownCss = { "border","background-color","border-collapse","width","height"}; "border","background-color","border-collapse","width","height", "display","visibility"}; std::string custom = extractCustomCss(cssProps, knownCss, mediaRules, cssClass, elemId); if (!custom.empty()) { tinyxml2::XMLElement *ccEl = doc.NewElement("CustomCss"); Loading Loading @@ -1232,11 +1239,21 @@ void blogi::htmlimport::htmlElementToWidgetXml( if (cssProps.count("border-radius")) w->SetAttribute("border_radius", cssProps["border-radius"].c_str()); if (cssProps.count("border")) w->SetAttribute("border_style", cssProps["border"].c_str()); if (cssProps.count("text-align")) w->SetAttribute("text_align", cssProps["text-align"].c_str()); if (cssProps.count("width")) w->SetAttribute("width", cssProps["width"].c_str()); if (cssProps.count("height")) w->SetAttribute("height", cssProps["height"].c_str()); if (cssMeansHidden(cssProps)) w->SetAttribute("hidden", "true"); std::vector<std::string> knownCss = { "background-color","color","font-size","padding", "border-radius","border","width","height","display", "text-decoration","cursor","text-align"}; "visibility","text-decoration","cursor","text-align"}; std::string custom = extractCustomCss(cssProps, knownCss, mediaRules, cssClass, elemId); if (!custom.empty()) { tinyxml2::XMLElement *ccEl = doc.NewElement("CustomCss"); Loading tests/htmlimport_smoke.cpp +39 −0 Original line number Diff line number Diff line Loading @@ -331,6 +331,45 @@ int main(){ "an unset custom property falls back to var()'s fallback argument"); } // --- Button (<a> with no child elements) CSS properties reach the // Button widget's own attributes instead of being silently dropped --- std::cout << "=== Button CSS properties ===" << std::endl; { std::string html = "<a href=\"#\" style=\"border: 2px solid red; text-align: right; " "width: 150px; height: 40px; display:none\">Click</a>"; std::string xml = importXml(html); check(xml.find("<Button") != std::string::npos, "a childless <a> still produces a Button widget"); check(xml.find("border_style=\"2px solid red\"") != std::string::npos, "border reaches the Button's border_style attribute (previously silently dropped)"); check(xml.find("text_align=\"right\"") != std::string::npos, "text-align reaches the Button's text_align attribute (previously silently dropped)"); check(xml.find("width=\"150px\"") != std::string::npos, "width reaches the Button's width attribute (previously silently dropped)"); check(xml.find("height=\"40px\"") != std::string::npos, "height reaches the Button's height attribute (previously silently dropped)"); check(xml.find("hidden=\"true\"") != std::string::npos, "display:none on a Button maps to hidden=\"true\" (previously silently dropped)"); } // --- Table CSS properties reach the Table widget's own attributes --- std::cout << "=== Table CSS properties ===" << std::endl; { std::string html = "<table style=\"width: 300px; height: 200px; visibility:hidden\">" "<tr><td>a</td></tr></table>"; std::string xml = importXml(html); check(xml.find("<Table") != std::string::npos, "a <table> still produces a Table widget"); check(xml.find("width=\"300px\"") != std::string::npos, "width reaches the Table's width attribute (previously silently dropped)"); check(xml.find("height=\"200px\"") != std::string::npos, "height reaches the Table's height attribute (previously silently dropped)"); check(xml.find("hidden=\"true\"") != std::string::npos, "visibility:hidden on a Table maps to hidden=\"true\" (previously silently dropped)"); } // --- Summary --- std::cout << "\n=== " << passCount << "/" << testCount << " tests passed ===" << std::endl; Loading Loading
editor/src/htmlimport.cpp +19 −2 Original line number Diff line number Diff line Loading @@ -1045,6 +1045,12 @@ void blogi::htmlimport::htmlElementToWidgetXml( if (cssProps.count("background-color")) w->SetAttribute("background_color", cssProps["background-color"].c_str()); if (cssProps.count("width")) w->SetAttribute("width", cssProps["width"].c_str()); if (cssProps.count("height")) w->SetAttribute("height", cssProps["height"].c_str()); if (cssMeansHidden(cssProps)) w->SetAttribute("hidden", "true"); int numRows = 0, numCols = 0; bool hasHeader = false; Loading Loading @@ -1144,7 +1150,8 @@ void blogi::htmlimport::htmlElementToWidgetXml( } std::vector<std::string> knownCss = { "border","background-color","border-collapse","width","height"}; "border","background-color","border-collapse","width","height", "display","visibility"}; std::string custom = extractCustomCss(cssProps, knownCss, mediaRules, cssClass, elemId); if (!custom.empty()) { tinyxml2::XMLElement *ccEl = doc.NewElement("CustomCss"); Loading Loading @@ -1232,11 +1239,21 @@ void blogi::htmlimport::htmlElementToWidgetXml( if (cssProps.count("border-radius")) w->SetAttribute("border_radius", cssProps["border-radius"].c_str()); if (cssProps.count("border")) w->SetAttribute("border_style", cssProps["border"].c_str()); if (cssProps.count("text-align")) w->SetAttribute("text_align", cssProps["text-align"].c_str()); if (cssProps.count("width")) w->SetAttribute("width", cssProps["width"].c_str()); if (cssProps.count("height")) w->SetAttribute("height", cssProps["height"].c_str()); if (cssMeansHidden(cssProps)) w->SetAttribute("hidden", "true"); std::vector<std::string> knownCss = { "background-color","color","font-size","padding", "border-radius","border","width","height","display", "text-decoration","cursor","text-align"}; "visibility","text-decoration","cursor","text-align"}; std::string custom = extractCustomCss(cssProps, knownCss, mediaRules, cssClass, elemId); if (!custom.empty()) { tinyxml2::XMLElement *ccEl = doc.NewElement("CustomCss"); Loading
tests/htmlimport_smoke.cpp +39 −0 Original line number Diff line number Diff line Loading @@ -331,6 +331,45 @@ int main(){ "an unset custom property falls back to var()'s fallback argument"); } // --- Button (<a> with no child elements) CSS properties reach the // Button widget's own attributes instead of being silently dropped --- std::cout << "=== Button CSS properties ===" << std::endl; { std::string html = "<a href=\"#\" style=\"border: 2px solid red; text-align: right; " "width: 150px; height: 40px; display:none\">Click</a>"; std::string xml = importXml(html); check(xml.find("<Button") != std::string::npos, "a childless <a> still produces a Button widget"); check(xml.find("border_style=\"2px solid red\"") != std::string::npos, "border reaches the Button's border_style attribute (previously silently dropped)"); check(xml.find("text_align=\"right\"") != std::string::npos, "text-align reaches the Button's text_align attribute (previously silently dropped)"); check(xml.find("width=\"150px\"") != std::string::npos, "width reaches the Button's width attribute (previously silently dropped)"); check(xml.find("height=\"40px\"") != std::string::npos, "height reaches the Button's height attribute (previously silently dropped)"); check(xml.find("hidden=\"true\"") != std::string::npos, "display:none on a Button maps to hidden=\"true\" (previously silently dropped)"); } // --- Table CSS properties reach the Table widget's own attributes --- std::cout << "=== Table CSS properties ===" << std::endl; { std::string html = "<table style=\"width: 300px; height: 200px; visibility:hidden\">" "<tr><td>a</td></tr></table>"; std::string xml = importXml(html); check(xml.find("<Table") != std::string::npos, "a <table> still produces a Table widget"); check(xml.find("width=\"300px\"") != std::string::npos, "width reaches the Table's width attribute (previously silently dropped)"); check(xml.find("height=\"200px\"") != std::string::npos, "height reaches the Table's height attribute (previously silently dropped)"); check(xml.find("hidden=\"true\"") != std::string::npos, "visibility:hidden on a Table maps to hidden=\"true\" (previously silently dropped)"); } // --- Summary --- std::cout << "\n=== " << passCount << "/" << testCount << " tests passed ===" << std::endl; Loading