#include "utils.h" #include #include #include void Utils::newline_to_br(std::string *str) { str_replace(str, "\r\n", "
"); str_replace(str, "\n", "
"); } void Utils::markdown_to_html(std::string *str) { std::shared_ptr config = std::make_shared(); config->isEmphasizedParserEnabled = true; config->isHTMLWrappedInParagraph = true; std::shared_ptr parser = std::make_shared(config); std::stringstream ss((*str)); std::string htmlOutput = parser->Parse(ss); (*str) = htmlOutput; } void Utils::str_replace(std::string *str, const std::string &from, const std::string &to) { if (from.empty()) return; size_t start_pos = 0; while ((start_pos = str->find(from, start_pos)) != std::string::npos) { str->replace(start_pos, from.length(), to); start_pos += to.length(); } }