use QString as buf in rainbowifyer

This commit is contained in:
LordMZTE 2021-03-28 14:14:05 +02:00
parent 4e6150f28e
commit e7f20eeae0

View file

@ -510,7 +510,7 @@ utils::markdownToHtml(const QString &text, bool rainbowify)
// get text in current node // get text in current node
QString nodeText(cmark_node_get_literal(cur)); QString nodeText(cmark_node_get_literal(cur));
// create buffer to append rainbow text to // create buffer to append rainbow text to
std::string buf; QString buf;
int boundaryStart = 0; int boundaryStart = 0;
int boundaryEnd = 0; int boundaryEnd = 0;
// use QTextBoundaryFinder to iterate ofer graphemes // use QTextBoundaryFinder to iterate ofer graphemes
@ -523,7 +523,7 @@ utils::markdownToHtml(const QString &text, bool rainbowify)
boundaryStart = boundaryEnd; boundaryStart = boundaryEnd;
// Don't rainbowify whitespaces // Don't rainbowify whitespaces
if (curChar.trimmed().isEmpty()) { if (curChar.trimmed().isEmpty()) {
buf.append(curChar.toString().toStdString()); buf.append(curChar.toString());
continue; continue;
} }
@ -534,8 +534,7 @@ utils::markdownToHtml(const QString &text, bool rainbowify)
// create HTML element for current char // create HTML element for current char
auto curCharColored = QString("<font color=\"%0\">%1</font>") auto curCharColored = QString("<font color=\"%0\">%1</font>")
.arg(colorString) .arg(colorString)
.arg(curChar) .arg(curChar);
.toStdString();
// append colored HTML element to buffer // append colored HTML element to buffer
buf.append(curCharColored); buf.append(curCharColored);
@ -545,7 +544,7 @@ utils::markdownToHtml(const QString &text, bool rainbowify)
// create HTML_INLINE node to prevent HTML from being escaped // create HTML_INLINE node to prevent HTML from being escaped
auto htmlNode = cmark_node_new(CMARK_NODE_HTML_INLINE); auto htmlNode = cmark_node_new(CMARK_NODE_HTML_INLINE);
// set content of HTML node to buffer contents // set content of HTML node to buffer contents
cmark_node_set_literal(htmlNode, buf.c_str()); cmark_node_set_literal(htmlNode, buf.toUtf8().data());
// replace current node with HTML node // replace current node with HTML node
cmark_node_replace(cur, htmlNode); cmark_node_replace(cur, htmlNode);
// free memory of old node // free memory of old node