Loading editor/CMakeLists.txt +0 −2 Changes for editor/CMakeLists.txt: 0 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -21,8 +21,6 @@ if(NOT TARGET blogidev) find_package(json-c REQUIRED) find_package(tinyxml2 REQUIRED) find_package(libuuidp REQUIRED) find_package(fenrirds REQUIRED) find_package(libsmtppp REQUIRED) find_package(paritypp REQUIRED) find_package(ZLIB REQUIRED) add_definitions(-D${CMAKE_HOST_SYSTEM_NAME} -DWIN32_LEAN_AND_MEAN -DNOMINMAX) Loading editor/src/htmlimport.cpp +267 −0 Changes for editor/src/htmlimport.cpp: 267 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include <algorithm> #include <cctype> #include <cstring> #include <functional> #include <regex> #include <sstream> #include <stack> Loading Loading @@ -1058,6 +1059,129 @@ std::string blogi::htmlimport::rewriteCssUrls( return out; } // ---- Artikel-Bausteine (Ratgeber-Artikel, z.B. aus SchimmelScraper) ---- // FAQ (<details>/<summary>), Hinweiskasten (<aside>), HTML/CSS- // Balkendiagramm (<figure> mit .sb-bar-row) und Bild mit Bildunterschrift // (<figure><img><figcaption>) werden auf eigene Widgets abgebildet statt auf // Container/CustomHtml -- so bleiben sie im Editor bequem bearbeitbar. namespace { std::string articleLowerTag(libhtmlpp::HtmlElement *e) { std::string t = e->getTagname(); std::transform(t.begin(), t.end(), t.begin(), [](unsigned char c) { return std::tolower(c); }); return t; } bool articleHasClass(libhtmlpp::HtmlElement *e, const char *cls) { std::set<std::string> tokens; collectClassTokens(e->getAtributte("class"), tokens); return tokens.count(cls) > 0; } std::string articleTrim(const std::string &s) { size_t a = s.find_first_not_of(" \t\r\n"), b = s.find_last_not_of(" \t\r\n"); return a == std::string::npos ? "" : s.substr(a, b - a + 1); } // Sichtbarer Text eines Knotens und seiner Geschwister (ohne script/style) void articleText(libhtmlpp::Element *node, std::string &out) { for (; node; node = node->nextElement()) { int type = node->getType(); if (type == libhtmlpp::TextEl) { const std::string &t = static_cast<libhtmlpp::TextElement*>(node)->getText(); if (!t.empty()) { if (!out.empty() && out.back() != ' ' && t.front() != ' ') out += ' '; out += t; } } else if (type == libhtmlpp::HtmlEl) { auto *h = static_cast<libhtmlpp::HtmlElement*>(node); std::string tag = articleLowerTag(h); if (tag == "script" || tag == "style") continue; bool block = tag == "p" || tag == "li" || tag == "br" || tag == "div"; if (block && !out.empty() && out.back() != '\n') out += '\n'; articleText(h->firstChild(), out); } } } // Textknoten enthalten Entities roh ("&") -- fuer Widget-Attribute/Text, // die beim Speichern selbst wieder maskiert werden, dekodieren. std::string articleDecodeEntities(const std::string &in) { static const std::pair<const char*, const char*> named[] = { {"&", "&"}, {"<", "<"}, {">", ">"}, {""", "\""}, {"'", "'"}, {"'", "'"}, {" ", " "}, {"­", ""}, {"–", "\u2013"}, {"—", "\u2014"}}; std::string out; for (size_t i = 0; i < in.size();) { if (in[i] == '&') { bool hit = false; for (auto &n : named) { size_t len = std::strlen(n.first); if (in.compare(i, len, n.first) == 0) { out += n.second; i += len; hit = true; break; } } if (hit) continue; } out += in[i++]; } return out; } std::string articleTextOf(libhtmlpp::HtmlElement *e) { std::string out; if (e) articleText(e->firstChild(), out); out = articleDecodeEntities(out); // Mehrfache Leerzeichen/Zeilen zusammenfassen std::string res; for (char c : out) { if ((c == ' ' || c == '\t' || c == '\r') && !res.empty() && (res.back() == ' ' || res.back() == '\n')) continue; if (c == '\n' && !res.empty() && res.back() == ' ') res.pop_back(); if (c == '\n' && !res.empty() && res.back() == '\n') continue; res += (c == '\t' || c == '\r') ? ' ' : c; } return articleTrim(res); } void articleFindAll(libhtmlpp::Element *node, const std::function<bool(libhtmlpp::HtmlElement*)> &pred, std::vector<libhtmlpp::HtmlElement*> &out) { for (; node; node = node->nextElement()) { if (node->getType() != libhtmlpp::HtmlEl) continue; auto *h = static_cast<libhtmlpp::HtmlElement*>(node); if (pred(h)) out.push_back(h); articleFindAll(h->firstChild(), pred, out); } } libhtmlpp::HtmlElement *articleFind(libhtmlpp::HtmlElement *root, const std::function<bool(libhtmlpp::HtmlElement*)> &pred) { std::vector<libhtmlpp::HtmlElement*> all; if (root) articleFindAll(root->firstChild(), pred, all); return all.empty() ? nullptr : all.front(); } bool articleIsHeading(const std::string &tag) { return tag.size() == 2 && tag[0] == 'h' && tag[1] >= '1' && tag[1] <= '6'; } // "width:63.2%" -> "63.2" std::string articleWidthPercent(const std::string &style) { static const std::regex re(R"(width\s*:\s*([0-9]+(?:[.,][0-9]+)?)\s*%)", std::regex::icase); std::smatch m; if (!std::regex_search(style, m, re)) return ""; std::string v = m[1].str(); std::replace(v.begin(), v.end(), ',', '.'); return v; } } // namespace void blogi::htmlimport::htmlElementToWidgetXml( libhtmlpp::Element *htmlEl, tinyxml2::XMLDocument &doc, Loading Loading @@ -1153,6 +1277,149 @@ void blogi::htmlimport::htmlElementToWidgetXml( continue; } // ---- Artikel-Bausteine (siehe articleXxx-Helfer oben) ---- if (tag == "details") { // aufeinanderfolgende <details> = ein FAQ-Widget tinyxml2::XMLElement *w = doc.NewElement("FAQ"); w->SetAttribute("type_id", "c4e21a7f-b8d3-4f91-a2e6-9c0d5e3f7b28"); w->SetAttribute("title", ""); libhtmlpp::Element *it = cur; while (it && it != stop) { if (it->getType() == libhtmlpp::TextEl) { const std::string &t = static_cast<libhtmlpp::TextElement*>(it)->getText(); if (t.find_first_not_of(" \t\r\n") != std::string::npos) break; it = it->nextElement(); continue; } if (it->getType() == libhtmlpp::CommentEl) { it = it->nextElement(); continue; } if (it->getType() != libhtmlpp::HtmlEl) break; auto *d = static_cast<libhtmlpp::HtmlElement*>(it); if (articleLowerTag(d) != "details") break; std::string question, answer; for (libhtmlpp::Element *c = d->firstChild(); c; c = c->nextElement()) { if (c->getType() == libhtmlpp::HtmlEl && articleLowerTag(static_cast<libhtmlpp::HtmlElement*>(c)) == "summary") { question = articleTextOf(static_cast<libhtmlpp::HtmlElement*>(c)); } else if (c->getType() == libhtmlpp::HtmlEl) { std::string part = articleTextOf(static_cast<libhtmlpp::HtmlElement*>(c)); if (!part.empty()) answer += (answer.empty() ? "" : "\n\n") + part; } else if (c->getType() == libhtmlpp::TextEl) { std::string part = articleTrim(static_cast<libhtmlpp::TextElement*>(c)->getText()); if (!part.empty()) answer += (answer.empty() ? "" : "\n\n") + part; } } if (!question.empty()) { tinyxml2::XMLElement *item = doc.NewElement("FAQItem"); item->SetAttribute("question", question.c_str()); item->SetAttribute("answer", answer.c_str()); w->InsertEndChild(item); } it = it->nextElement(); } pXml->InsertEndChild(w); cur = it; continue; } if (tag == "aside") { // Kasten ("Das Wichtigste in Kürze"): nur, wenn er wie ein // Kasten aussieht -- Seitenleisten (nav/form/Bilder) bleiben // Sections wie bisher. bool boxLike = !articleFind(el, [](libhtmlpp::HtmlElement *h) { std::string t = articleLowerTag(h); return t == "nav" || t == "form" || t == "img" || t == "section" || t == "aside"; }); std::string inner = serializeInnerHtml(el); if (boxLike && inner.size() < 8000) { tinyxml2::XMLElement *w = doc.NewElement("InfoBox"); w->SetAttribute("type_id", "61a4426e-70f8-46e2-ac43-ca4e648f61dc"); w->SetAttribute("variant", "summary"); std::string title, content; for (libhtmlpp::Element *c = el->firstChild(); c; c = c->nextElement()) { if (c->getType() == libhtmlpp::HtmlEl) { auto *h = static_cast<libhtmlpp::HtmlElement*>(c); std::string t = articleLowerTag(h); // erste Ueberschrift (oder fetter Einzeiler) = Titel if (title.empty() && articleTrim(content).empty() && (articleIsHeading(t) || t == "strong" || t == "b" || (t == "p" && h->firstChild() && h->firstChild()->getType() == libhtmlpp::HtmlEl && !h->firstChild()->nextElement() && (articleLowerTag(static_cast<libhtmlpp::HtmlElement*>(h->firstChild())) == "strong" || articleLowerTag(static_cast<libhtmlpp::HtmlElement*>(h->firstChild())) == "b")))) { title = articleTextOf(h); continue; } } content += serializeElement(c); } w->SetAttribute("title", title.c_str()); tinyxml2::XMLElement *ce = doc.NewElement("Content"); ce->SetText(articleTrim(content).c_str()); w->InsertEndChild(ce); pXml->InsertEndChild(w); cur = cur->nextElement(); continue; } } if (tag == "figure") { std::vector<libhtmlpp::HtmlElement*> barRows; articleFindAll(el->firstChild(), [](libhtmlpp::HtmlElement *h) { return articleHasClass(h, "sb-bar-row"); }, barRows); libhtmlpp::HtmlElement *figcap = articleFind(el, [](libhtmlpp::HtmlElement *h) { return articleLowerTag(h) == "figcaption"; }); if (!barRows.empty()) { // HTML/CSS-Balkendiagramm -> BarChart (Werte editierbar) tinyxml2::XMLElement *w = doc.NewElement("BarChart"); w->SetAttribute("type_id", "696e9dd0-92c3-497e-955e-bd5341cf021c"); std::string rows; for (auto *row : barRows) { auto *lab = articleFind(row, [](libhtmlpp::HtmlElement *h) { return articleHasClass(h, "sb-bar-label"); }); auto *bar = articleFind(row, [](libhtmlpp::HtmlElement *h) { return articleHasClass(h, "sb-bar"); }); std::string label = lab ? articleTextOf(lab) : articleTextOf(row); std::string val = bar ? articleWidthPercent(bar->getAtributte("style")) : ""; if (val.empty()) { // Breite fehlt: Prozentwert aus der Beschriftung ("... (11,9 %)") static const std::regex pct(R"(([0-9]+(?:[.,][0-9]+)?)\s*%)"); for (std::sregex_iterator m(label.begin(), label.end(), pct), end; m != end; ++m) val = (*m)[1].str(); std::replace(val.begin(), val.end(), ',', '.'); } for (auto &ch : label) if (ch == '|' || ch == '\n') ch = ' '; if (!label.empty()) rows += label + " | " + (val.empty() ? "0" : val) + "\n"; } auto *heading = articleFind(el, [](libhtmlpp::HtmlElement *h) { return articleIsHeading(articleLowerTag(h)); }); w->SetAttribute("title", heading ? articleTextOf(heading).c_str() : ""); w->SetAttribute("unit", "%"); w->SetAttribute("max", "100"); // Die Bezeichnungen enthalten die Zahlen bereits w->SetAttribute("show_values", "false"); w->SetAttribute("caption", figcap ? articleTextOf(figcap).c_str() : ""); tinyxml2::XMLElement *re = doc.NewElement("Rows"); re->SetText(rows.c_str()); w->InsertEndChild(re); pXml->InsertEndChild(w); cur = cur->nextElement(); continue; } auto *img = articleFind(el, [](libhtmlpp::HtmlElement *h) { return articleLowerTag(h) == "img"; }); if (img && figcap) { // Foto mit Bildunterschrift -> Image mit caption tinyxml2::XMLElement *w = doc.NewElement("Image"); w->SetAttribute("src", img->getAtributte("src").c_str()); w->SetAttribute("alt", img->getAtributte("alt").c_str()); w->SetAttribute("caption", articleTextOf(figcap).c_str()); w->SetAttribute("width", "100%"); w->SetAttribute("height", "auto"); w->SetAttribute("object_fit", "contain"); pXml->InsertEndChild(w); cur = cur->nextElement(); continue; } } // Raw inline style text -- kept for the CustomHtml fallback // branch further below, which embeds it verbatim regardless of // whether libhtmlpp could parse/match anything out of it. Loading editor/src/webedit_api.cpp +21 −2 Changes for editor/src/webedit_api.cpp: 21 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -6203,7 +6203,8 @@ json_object *webedit::Api::mcpPublishToConnection(const std::string &authid, const std::string &domain, const std::string &docId, const std::string &connId, const std::string &target) { const std::string &target, json_object *params) { if (target.empty()) throw McpError(400, "Missing 'target' (publish target name)"); Loading @@ -6216,10 +6217,28 @@ json_object *webedit::Api::mcpPublishToConnection(const std::string &authid, DocumentState doc; mcpLoadDocument(domain, docId, doc); // Ohne params kamen bisher nur llms_txt beim Blog an -- das content-Ziel // lehnt dann ab ("Title and description are required"). Jetzt: explizit // uebergebene params (z.B. title/description/tags), sonst die am Dokument // gespeicherten des letzten Veroeffentlichens auf dieses Ziel (wie der // Veroeffentlichen-Dialog des Editors). json_object *ownParams = nullptr; if (params && json_object_is_type(params, json_type_object)) { ownParams = json_object_get(params); } else { auto it = doc.publishParams.find(target); if (it != doc.publishParams.end() && !it->second.empty()) ownParams = json_tokener_parse(it->second.c_str()); } auto result = publishToConnectionCore(authid, connectResult.blogUrl, domain, connId, doc, target, nullptr); doc, target, ownParams); if (ownParams) json_object_put(ownParams); if (!result.ok) throw McpError(result.httpStatus, result.message); // publishToConnectionCore hat lastPublishTarget/publishParams am Dokument // aktualisiert -- speichern, damit der Editor-Dialog sie vorbelegt. mcpSaveDocument(domain, docId, doc); json_object *resp = json_object_new_object(); json_object_object_add(resp, "status", json_object_new_string(result.status.c_str())); Loading editor/src/webedit_api.h +2 −1 Changes for editor/src/webedit_api.h: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -102,7 +102,8 @@ namespace webedit { const std::string &connId); json_object *mcpPublishToConnection(const std::string &authid, const std::string &domain, const std::string &docId, const std::string &connId, const std::string &target); const std::string &target, json_object *params = nullptr); // MCP API token management — browser-session (cookie) authenticated, // used from the editor's Settings UI to issue/revoke tokens for /mcp. Loading editor/src/webedit_mcp.cpp +5 −2 Changes for editor/src/webedit_mcp.cpp: 5 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -356,7 +356,7 @@ json_object *webedit::Mcp::callTool(const std::string &name, json_object *args, } else if (name == "publish_to_connection") { payload = _api.mcpPublishToConnection(authid, domain, getStringArg(args, "document_id"), getStringArg(args, "connection_id"), getStringArg(args, "target")); getStringArg(args, "target"), getObjectArg(args, "params")); } else { json_object *err = json_object_new_object(); json_object_object_add(err, "error", Loading Loading @@ -496,11 +496,14 @@ json_object *webedit::Mcp::toolsListResult() { json_object_array_add(tools, makeTool("publish_to_connection", "Log into a saved blog connection and publish a document's rendered HTML to one of its " "publish targets (see list_publish_targets).", "publish targets (see list_publish_targets). Optional params are the target's publish " "form fields (e.g. for content: title, description, tags, og_image, overwrite); " "without them the params saved on the document from its last publish are used.", makeSchema({ {"document_id", "string", ""}, {"connection_id", "string", ""}, {"target", "string", "Publish target name from list_publish_targets"}, {"params", "object", "Publish form fields for the target (optional)"}, }, {"document_id", "connection_id", "target"}))); json_object *result = json_object_new_object(); Loading Loading
editor/CMakeLists.txt +0 −2 Changes for editor/CMakeLists.txt: 0 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -21,8 +21,6 @@ if(NOT TARGET blogidev) find_package(json-c REQUIRED) find_package(tinyxml2 REQUIRED) find_package(libuuidp REQUIRED) find_package(fenrirds REQUIRED) find_package(libsmtppp REQUIRED) find_package(paritypp REQUIRED) find_package(ZLIB REQUIRED) add_definitions(-D${CMAKE_HOST_SYSTEM_NAME} -DWIN32_LEAN_AND_MEAN -DNOMINMAX) Loading
editor/src/htmlimport.cpp +267 −0 Changes for editor/src/htmlimport.cpp: 267 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include <algorithm> #include <cctype> #include <cstring> #include <functional> #include <regex> #include <sstream> #include <stack> Loading Loading @@ -1058,6 +1059,129 @@ std::string blogi::htmlimport::rewriteCssUrls( return out; } // ---- Artikel-Bausteine (Ratgeber-Artikel, z.B. aus SchimmelScraper) ---- // FAQ (<details>/<summary>), Hinweiskasten (<aside>), HTML/CSS- // Balkendiagramm (<figure> mit .sb-bar-row) und Bild mit Bildunterschrift // (<figure><img><figcaption>) werden auf eigene Widgets abgebildet statt auf // Container/CustomHtml -- so bleiben sie im Editor bequem bearbeitbar. namespace { std::string articleLowerTag(libhtmlpp::HtmlElement *e) { std::string t = e->getTagname(); std::transform(t.begin(), t.end(), t.begin(), [](unsigned char c) { return std::tolower(c); }); return t; } bool articleHasClass(libhtmlpp::HtmlElement *e, const char *cls) { std::set<std::string> tokens; collectClassTokens(e->getAtributte("class"), tokens); return tokens.count(cls) > 0; } std::string articleTrim(const std::string &s) { size_t a = s.find_first_not_of(" \t\r\n"), b = s.find_last_not_of(" \t\r\n"); return a == std::string::npos ? "" : s.substr(a, b - a + 1); } // Sichtbarer Text eines Knotens und seiner Geschwister (ohne script/style) void articleText(libhtmlpp::Element *node, std::string &out) { for (; node; node = node->nextElement()) { int type = node->getType(); if (type == libhtmlpp::TextEl) { const std::string &t = static_cast<libhtmlpp::TextElement*>(node)->getText(); if (!t.empty()) { if (!out.empty() && out.back() != ' ' && t.front() != ' ') out += ' '; out += t; } } else if (type == libhtmlpp::HtmlEl) { auto *h = static_cast<libhtmlpp::HtmlElement*>(node); std::string tag = articleLowerTag(h); if (tag == "script" || tag == "style") continue; bool block = tag == "p" || tag == "li" || tag == "br" || tag == "div"; if (block && !out.empty() && out.back() != '\n') out += '\n'; articleText(h->firstChild(), out); } } } // Textknoten enthalten Entities roh ("&") -- fuer Widget-Attribute/Text, // die beim Speichern selbst wieder maskiert werden, dekodieren. std::string articleDecodeEntities(const std::string &in) { static const std::pair<const char*, const char*> named[] = { {"&", "&"}, {"<", "<"}, {">", ">"}, {""", "\""}, {"'", "'"}, {"'", "'"}, {" ", " "}, {"­", ""}, {"–", "\u2013"}, {"—", "\u2014"}}; std::string out; for (size_t i = 0; i < in.size();) { if (in[i] == '&') { bool hit = false; for (auto &n : named) { size_t len = std::strlen(n.first); if (in.compare(i, len, n.first) == 0) { out += n.second; i += len; hit = true; break; } } if (hit) continue; } out += in[i++]; } return out; } std::string articleTextOf(libhtmlpp::HtmlElement *e) { std::string out; if (e) articleText(e->firstChild(), out); out = articleDecodeEntities(out); // Mehrfache Leerzeichen/Zeilen zusammenfassen std::string res; for (char c : out) { if ((c == ' ' || c == '\t' || c == '\r') && !res.empty() && (res.back() == ' ' || res.back() == '\n')) continue; if (c == '\n' && !res.empty() && res.back() == ' ') res.pop_back(); if (c == '\n' && !res.empty() && res.back() == '\n') continue; res += (c == '\t' || c == '\r') ? ' ' : c; } return articleTrim(res); } void articleFindAll(libhtmlpp::Element *node, const std::function<bool(libhtmlpp::HtmlElement*)> &pred, std::vector<libhtmlpp::HtmlElement*> &out) { for (; node; node = node->nextElement()) { if (node->getType() != libhtmlpp::HtmlEl) continue; auto *h = static_cast<libhtmlpp::HtmlElement*>(node); if (pred(h)) out.push_back(h); articleFindAll(h->firstChild(), pred, out); } } libhtmlpp::HtmlElement *articleFind(libhtmlpp::HtmlElement *root, const std::function<bool(libhtmlpp::HtmlElement*)> &pred) { std::vector<libhtmlpp::HtmlElement*> all; if (root) articleFindAll(root->firstChild(), pred, all); return all.empty() ? nullptr : all.front(); } bool articleIsHeading(const std::string &tag) { return tag.size() == 2 && tag[0] == 'h' && tag[1] >= '1' && tag[1] <= '6'; } // "width:63.2%" -> "63.2" std::string articleWidthPercent(const std::string &style) { static const std::regex re(R"(width\s*:\s*([0-9]+(?:[.,][0-9]+)?)\s*%)", std::regex::icase); std::smatch m; if (!std::regex_search(style, m, re)) return ""; std::string v = m[1].str(); std::replace(v.begin(), v.end(), ',', '.'); return v; } } // namespace void blogi::htmlimport::htmlElementToWidgetXml( libhtmlpp::Element *htmlEl, tinyxml2::XMLDocument &doc, Loading Loading @@ -1153,6 +1277,149 @@ void blogi::htmlimport::htmlElementToWidgetXml( continue; } // ---- Artikel-Bausteine (siehe articleXxx-Helfer oben) ---- if (tag == "details") { // aufeinanderfolgende <details> = ein FAQ-Widget tinyxml2::XMLElement *w = doc.NewElement("FAQ"); w->SetAttribute("type_id", "c4e21a7f-b8d3-4f91-a2e6-9c0d5e3f7b28"); w->SetAttribute("title", ""); libhtmlpp::Element *it = cur; while (it && it != stop) { if (it->getType() == libhtmlpp::TextEl) { const std::string &t = static_cast<libhtmlpp::TextElement*>(it)->getText(); if (t.find_first_not_of(" \t\r\n") != std::string::npos) break; it = it->nextElement(); continue; } if (it->getType() == libhtmlpp::CommentEl) { it = it->nextElement(); continue; } if (it->getType() != libhtmlpp::HtmlEl) break; auto *d = static_cast<libhtmlpp::HtmlElement*>(it); if (articleLowerTag(d) != "details") break; std::string question, answer; for (libhtmlpp::Element *c = d->firstChild(); c; c = c->nextElement()) { if (c->getType() == libhtmlpp::HtmlEl && articleLowerTag(static_cast<libhtmlpp::HtmlElement*>(c)) == "summary") { question = articleTextOf(static_cast<libhtmlpp::HtmlElement*>(c)); } else if (c->getType() == libhtmlpp::HtmlEl) { std::string part = articleTextOf(static_cast<libhtmlpp::HtmlElement*>(c)); if (!part.empty()) answer += (answer.empty() ? "" : "\n\n") + part; } else if (c->getType() == libhtmlpp::TextEl) { std::string part = articleTrim(static_cast<libhtmlpp::TextElement*>(c)->getText()); if (!part.empty()) answer += (answer.empty() ? "" : "\n\n") + part; } } if (!question.empty()) { tinyxml2::XMLElement *item = doc.NewElement("FAQItem"); item->SetAttribute("question", question.c_str()); item->SetAttribute("answer", answer.c_str()); w->InsertEndChild(item); } it = it->nextElement(); } pXml->InsertEndChild(w); cur = it; continue; } if (tag == "aside") { // Kasten ("Das Wichtigste in Kürze"): nur, wenn er wie ein // Kasten aussieht -- Seitenleisten (nav/form/Bilder) bleiben // Sections wie bisher. bool boxLike = !articleFind(el, [](libhtmlpp::HtmlElement *h) { std::string t = articleLowerTag(h); return t == "nav" || t == "form" || t == "img" || t == "section" || t == "aside"; }); std::string inner = serializeInnerHtml(el); if (boxLike && inner.size() < 8000) { tinyxml2::XMLElement *w = doc.NewElement("InfoBox"); w->SetAttribute("type_id", "61a4426e-70f8-46e2-ac43-ca4e648f61dc"); w->SetAttribute("variant", "summary"); std::string title, content; for (libhtmlpp::Element *c = el->firstChild(); c; c = c->nextElement()) { if (c->getType() == libhtmlpp::HtmlEl) { auto *h = static_cast<libhtmlpp::HtmlElement*>(c); std::string t = articleLowerTag(h); // erste Ueberschrift (oder fetter Einzeiler) = Titel if (title.empty() && articleTrim(content).empty() && (articleIsHeading(t) || t == "strong" || t == "b" || (t == "p" && h->firstChild() && h->firstChild()->getType() == libhtmlpp::HtmlEl && !h->firstChild()->nextElement() && (articleLowerTag(static_cast<libhtmlpp::HtmlElement*>(h->firstChild())) == "strong" || articleLowerTag(static_cast<libhtmlpp::HtmlElement*>(h->firstChild())) == "b")))) { title = articleTextOf(h); continue; } } content += serializeElement(c); } w->SetAttribute("title", title.c_str()); tinyxml2::XMLElement *ce = doc.NewElement("Content"); ce->SetText(articleTrim(content).c_str()); w->InsertEndChild(ce); pXml->InsertEndChild(w); cur = cur->nextElement(); continue; } } if (tag == "figure") { std::vector<libhtmlpp::HtmlElement*> barRows; articleFindAll(el->firstChild(), [](libhtmlpp::HtmlElement *h) { return articleHasClass(h, "sb-bar-row"); }, barRows); libhtmlpp::HtmlElement *figcap = articleFind(el, [](libhtmlpp::HtmlElement *h) { return articleLowerTag(h) == "figcaption"; }); if (!barRows.empty()) { // HTML/CSS-Balkendiagramm -> BarChart (Werte editierbar) tinyxml2::XMLElement *w = doc.NewElement("BarChart"); w->SetAttribute("type_id", "696e9dd0-92c3-497e-955e-bd5341cf021c"); std::string rows; for (auto *row : barRows) { auto *lab = articleFind(row, [](libhtmlpp::HtmlElement *h) { return articleHasClass(h, "sb-bar-label"); }); auto *bar = articleFind(row, [](libhtmlpp::HtmlElement *h) { return articleHasClass(h, "sb-bar"); }); std::string label = lab ? articleTextOf(lab) : articleTextOf(row); std::string val = bar ? articleWidthPercent(bar->getAtributte("style")) : ""; if (val.empty()) { // Breite fehlt: Prozentwert aus der Beschriftung ("... (11,9 %)") static const std::regex pct(R"(([0-9]+(?:[.,][0-9]+)?)\s*%)"); for (std::sregex_iterator m(label.begin(), label.end(), pct), end; m != end; ++m) val = (*m)[1].str(); std::replace(val.begin(), val.end(), ',', '.'); } for (auto &ch : label) if (ch == '|' || ch == '\n') ch = ' '; if (!label.empty()) rows += label + " | " + (val.empty() ? "0" : val) + "\n"; } auto *heading = articleFind(el, [](libhtmlpp::HtmlElement *h) { return articleIsHeading(articleLowerTag(h)); }); w->SetAttribute("title", heading ? articleTextOf(heading).c_str() : ""); w->SetAttribute("unit", "%"); w->SetAttribute("max", "100"); // Die Bezeichnungen enthalten die Zahlen bereits w->SetAttribute("show_values", "false"); w->SetAttribute("caption", figcap ? articleTextOf(figcap).c_str() : ""); tinyxml2::XMLElement *re = doc.NewElement("Rows"); re->SetText(rows.c_str()); w->InsertEndChild(re); pXml->InsertEndChild(w); cur = cur->nextElement(); continue; } auto *img = articleFind(el, [](libhtmlpp::HtmlElement *h) { return articleLowerTag(h) == "img"; }); if (img && figcap) { // Foto mit Bildunterschrift -> Image mit caption tinyxml2::XMLElement *w = doc.NewElement("Image"); w->SetAttribute("src", img->getAtributte("src").c_str()); w->SetAttribute("alt", img->getAtributte("alt").c_str()); w->SetAttribute("caption", articleTextOf(figcap).c_str()); w->SetAttribute("width", "100%"); w->SetAttribute("height", "auto"); w->SetAttribute("object_fit", "contain"); pXml->InsertEndChild(w); cur = cur->nextElement(); continue; } } // Raw inline style text -- kept for the CustomHtml fallback // branch further below, which embeds it verbatim regardless of // whether libhtmlpp could parse/match anything out of it. Loading
editor/src/webedit_api.cpp +21 −2 Changes for editor/src/webedit_api.cpp: 21 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -6203,7 +6203,8 @@ json_object *webedit::Api::mcpPublishToConnection(const std::string &authid, const std::string &domain, const std::string &docId, const std::string &connId, const std::string &target) { const std::string &target, json_object *params) { if (target.empty()) throw McpError(400, "Missing 'target' (publish target name)"); Loading @@ -6216,10 +6217,28 @@ json_object *webedit::Api::mcpPublishToConnection(const std::string &authid, DocumentState doc; mcpLoadDocument(domain, docId, doc); // Ohne params kamen bisher nur llms_txt beim Blog an -- das content-Ziel // lehnt dann ab ("Title and description are required"). Jetzt: explizit // uebergebene params (z.B. title/description/tags), sonst die am Dokument // gespeicherten des letzten Veroeffentlichens auf dieses Ziel (wie der // Veroeffentlichen-Dialog des Editors). json_object *ownParams = nullptr; if (params && json_object_is_type(params, json_type_object)) { ownParams = json_object_get(params); } else { auto it = doc.publishParams.find(target); if (it != doc.publishParams.end() && !it->second.empty()) ownParams = json_tokener_parse(it->second.c_str()); } auto result = publishToConnectionCore(authid, connectResult.blogUrl, domain, connId, doc, target, nullptr); doc, target, ownParams); if (ownParams) json_object_put(ownParams); if (!result.ok) throw McpError(result.httpStatus, result.message); // publishToConnectionCore hat lastPublishTarget/publishParams am Dokument // aktualisiert -- speichern, damit der Editor-Dialog sie vorbelegt. mcpSaveDocument(domain, docId, doc); json_object *resp = json_object_new_object(); json_object_object_add(resp, "status", json_object_new_string(result.status.c_str())); Loading
editor/src/webedit_api.h +2 −1 Changes for editor/src/webedit_api.h: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -102,7 +102,8 @@ namespace webedit { const std::string &connId); json_object *mcpPublishToConnection(const std::string &authid, const std::string &domain, const std::string &docId, const std::string &connId, const std::string &target); const std::string &target, json_object *params = nullptr); // MCP API token management — browser-session (cookie) authenticated, // used from the editor's Settings UI to issue/revoke tokens for /mcp. Loading
editor/src/webedit_mcp.cpp +5 −2 Changes for editor/src/webedit_mcp.cpp: 5 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -356,7 +356,7 @@ json_object *webedit::Mcp::callTool(const std::string &name, json_object *args, } else if (name == "publish_to_connection") { payload = _api.mcpPublishToConnection(authid, domain, getStringArg(args, "document_id"), getStringArg(args, "connection_id"), getStringArg(args, "target")); getStringArg(args, "target"), getObjectArg(args, "params")); } else { json_object *err = json_object_new_object(); json_object_object_add(err, "error", Loading Loading @@ -496,11 +496,14 @@ json_object *webedit::Mcp::toolsListResult() { json_object_array_add(tools, makeTool("publish_to_connection", "Log into a saved blog connection and publish a document's rendered HTML to one of its " "publish targets (see list_publish_targets).", "publish targets (see list_publish_targets). Optional params are the target's publish " "form fields (e.g. for content: title, description, tags, og_image, overwrite); " "without them the params saved on the document from its last publish are used.", makeSchema({ {"document_id", "string", ""}, {"connection_id", "string", ""}, {"target", "string", "Publish target name from list_publish_targets"}, {"params", "object", "Publish form fields for the target (optional)"}, }, {"document_id", "connection_id", "target"}))); json_object *result = json_object_new_object(); Loading