Loading src/edit.cpp +27 −19 Changes for src/edit.cpp: 27 added lines, 19 removed lines. Original line number Diff line number Diff line Loading @@ -488,30 +488,44 @@ void blogi::webedit::WebEditor::mergeStylesheetRules( if (start == std::string::npos) continue; singleSel = singleSel.substr(start, end - start + 1); // For compound/descendant selectors (e.g. "#parent .child > tag"), // extract the last simple selector and match against that. // This is an approximation but catches the vast majority of real-world CSS. std::string matchSel = singleSel; { // Find the last space, '>' or '+' combinator size_t lastSep = matchSel.find_last_of(" >+~"); if (lastSep != std::string::npos) { size_t mstart = matchSel.find_first_not_of(" >+~", lastSep); if (mstart != std::string::npos) { matchSel = matchSel.substr(mstart); } } } bool matches = false; // Simple selector matching (no combinators, just tag, .class, #id) if (!singleSel.empty() && singleSel[0] == '#') { if (!matchSel.empty() && matchSel[0] == '#') { // ID selector if (!id.empty() && singleSel == "#" + id) matches = true; } else if (!singleSel.empty() && singleSel[0] == '.') { if (!id.empty() && matchSel == "#" + id) matches = true; } else if (!matchSel.empty() && matchSel[0] == '.') { // Class selector std::string clsSel = singleSel.substr(1); std::string clsSel = matchSel.substr(1); for (const auto &c : classes) { if (c == clsSel) { matches = true; break; } } } else { // Tag selector (case-insensitive) std::string selLower = singleSel; std::string selLower = matchSel; std::transform(selLower.begin(), selLower.end(), selLower.begin(), [](unsigned char c) { return std::tolower(c); }); if (selLower == tag) matches = true; // Tag.class selector (e.g., "div.header") auto dotPos = singleSel.find('.'); auto dotPos = matchSel.find('.'); if (!matches && dotPos != std::string::npos) { std::string tagPart = singleSel.substr(0, dotPos); std::string clsPart = singleSel.substr(dotPos + 1); std::string tagPart = matchSel.substr(0, dotPos); std::string clsPart = matchSel.substr(dotPos + 1); std::transform(tagPart.begin(), tagPart.end(), tagPart.begin(), [](unsigned char c) { return std::tolower(c); }); if (tagPart == tag) { Loading @@ -522,10 +536,10 @@ void blogi::webedit::WebEditor::mergeStylesheetRules( } // Tag#id selector (e.g., "div#main") auto hashPos = singleSel.find('#'); auto hashPos = matchSel.find('#'); if (!matches && hashPos != std::string::npos) { std::string tagPart = singleSel.substr(0, hashPos); std::string idPart = singleSel.substr(hashPos + 1); std::string tagPart = matchSel.substr(0, hashPos); std::string idPart = matchSel.substr(hashPos + 1); std::transform(tagPart.begin(), tagPart.end(), tagPart.begin(), [](unsigned char c) { return std::tolower(c); }); if (tagPart == tag && idPart == id) matches = true; Loading Loading @@ -1049,13 +1063,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( pXml->InsertEndChild(w); } else if (tag == "style") { // Preserve full <style> block as CustomHtml so CSS rules apply at render time tinyxml2::XMLElement *w = doc.NewElement("CustomHtml"); tinyxml2::XMLElement *htmlContent = doc.NewElement("HtmlContent"); std::string styleHtml = "<style>" + serializeInnerHtml(el) + "</style>"; htmlContent->SetText(styleHtml.c_str()); w->InsertEndChild(htmlContent); pXml->InsertEndChild(w); // CSS rules already collected and applied via mergeStylesheetRules — skip } else if (tag == "br" || tag == "hr") { tinyxml2::XMLElement *w = doc.NewElement("CustomHtml"); Loading Loading
src/edit.cpp +27 −19 Changes for src/edit.cpp: 27 added lines, 19 removed lines. Original line number Diff line number Diff line Loading @@ -488,30 +488,44 @@ void blogi::webedit::WebEditor::mergeStylesheetRules( if (start == std::string::npos) continue; singleSel = singleSel.substr(start, end - start + 1); // For compound/descendant selectors (e.g. "#parent .child > tag"), // extract the last simple selector and match against that. // This is an approximation but catches the vast majority of real-world CSS. std::string matchSel = singleSel; { // Find the last space, '>' or '+' combinator size_t lastSep = matchSel.find_last_of(" >+~"); if (lastSep != std::string::npos) { size_t mstart = matchSel.find_first_not_of(" >+~", lastSep); if (mstart != std::string::npos) { matchSel = matchSel.substr(mstart); } } } bool matches = false; // Simple selector matching (no combinators, just tag, .class, #id) if (!singleSel.empty() && singleSel[0] == '#') { if (!matchSel.empty() && matchSel[0] == '#') { // ID selector if (!id.empty() && singleSel == "#" + id) matches = true; } else if (!singleSel.empty() && singleSel[0] == '.') { if (!id.empty() && matchSel == "#" + id) matches = true; } else if (!matchSel.empty() && matchSel[0] == '.') { // Class selector std::string clsSel = singleSel.substr(1); std::string clsSel = matchSel.substr(1); for (const auto &c : classes) { if (c == clsSel) { matches = true; break; } } } else { // Tag selector (case-insensitive) std::string selLower = singleSel; std::string selLower = matchSel; std::transform(selLower.begin(), selLower.end(), selLower.begin(), [](unsigned char c) { return std::tolower(c); }); if (selLower == tag) matches = true; // Tag.class selector (e.g., "div.header") auto dotPos = singleSel.find('.'); auto dotPos = matchSel.find('.'); if (!matches && dotPos != std::string::npos) { std::string tagPart = singleSel.substr(0, dotPos); std::string clsPart = singleSel.substr(dotPos + 1); std::string tagPart = matchSel.substr(0, dotPos); std::string clsPart = matchSel.substr(dotPos + 1); std::transform(tagPart.begin(), tagPart.end(), tagPart.begin(), [](unsigned char c) { return std::tolower(c); }); if (tagPart == tag) { Loading @@ -522,10 +536,10 @@ void blogi::webedit::WebEditor::mergeStylesheetRules( } // Tag#id selector (e.g., "div#main") auto hashPos = singleSel.find('#'); auto hashPos = matchSel.find('#'); if (!matches && hashPos != std::string::npos) { std::string tagPart = singleSel.substr(0, hashPos); std::string idPart = singleSel.substr(hashPos + 1); std::string tagPart = matchSel.substr(0, hashPos); std::string idPart = matchSel.substr(hashPos + 1); std::transform(tagPart.begin(), tagPart.end(), tagPart.begin(), [](unsigned char c) { return std::tolower(c); }); if (tagPart == tag && idPart == id) matches = true; Loading Loading @@ -1049,13 +1063,7 @@ void blogi::webedit::WebEditor::htmlElementToWidgetXml( pXml->InsertEndChild(w); } else if (tag == "style") { // Preserve full <style> block as CustomHtml so CSS rules apply at render time tinyxml2::XMLElement *w = doc.NewElement("CustomHtml"); tinyxml2::XMLElement *htmlContent = doc.NewElement("HtmlContent"); std::string styleHtml = "<style>" + serializeInnerHtml(el) + "</style>"; htmlContent->SetText(styleHtml.c_str()); w->InsertEndChild(htmlContent); pXml->InsertEndChild(w); // CSS rules already collected and applied via mergeStylesheetRules — skip } else if (tag == "br" || tag == "hr") { tinyxml2::XMLElement *w = doc.NewElement("CustomHtml"); Loading