#include "Comment.h" #include "Post.h" #include "Tag.h" #include "User.h" #include #include DBO_INSTANTIATE_TEMPLATES(Comment) static std::string &replace(std::string &s, const std::string &k, const std::string &r) { std::string::size_type p = 0; while ((p = s.find(k, p)) != std::string::npos) { s.replace(p, k.length(), r); p += r.length(); } return s; } void Comment::setText(const Wt::WString &text) { textSrc_ = text; std::string html = Wt::WWebWidget::escapeText(text, true).toUTF8(); std::string::size_type b = 0; // Replace <code>...</code> with
...
// This is kind of very ad-hoc! while ((b = html.find("<code>", b)) != std::string::npos) { std::string::size_type e = html.find("</code>", b); if (e == std::string::npos) break; else { if (b > 6 && html.substr(b - 6, 6) == "
") { html.erase(b - 6, 6); b -= 6; e -= 6; } html.replace(b, 12, "
");
            e -= 7;

            if (html.substr(b + 5, 6) == "
") { html.erase(b + 5, 6); e -= 6; } if (html.substr(e - 6, 6) == "
") { html.erase(e - 6, 6); e -= 6; } html.replace(e, 13, "
"); e += 6; if (e + 6 <= html.length() && html.substr(e, 6) == "
") { html.erase(e, 6); e -= 6; } b = e; } } // We would also want to replace

(empty line) with //
replace(html, "

", "
"); textHtml_ = Wt::WString(html); } void Comment::setDeleted() { textHtml_ = Wt::WString::tr("comment-deleted"); }