Moved html patch to StringUtils

Signed-off-by: SabrePenguin <lknofczynski@gmail.com>
This commit is contained in:
SabrePenguin 2024-04-30 22:40:04 -04:00 committed by Trial97
parent 0c84d58915
commit 401de52f61
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
3 changed files with 23 additions and 17 deletions

View File

@ -26,22 +26,6 @@ QString markdownToHTML(const QString& markdown)
QString htmlStr(buffer);
free(buffer);
int pos = htmlStr.indexOf("</ul>");
int imgPos;
while (pos != -1) {
pos = pos + 5; // 5 is the size of the </ul> tag
imgPos = htmlStr.indexOf("<img ", pos);
if (imgPos == -1)
break; // no image after the tag
auto textBetween = htmlStr.mid(pos, imgPos - pos).trimmed(); // trim all white spaces
if (textBetween.isEmpty())
htmlStr.insert(pos, "<br>");
pos = htmlStr.indexOf("</ul>", pos);
}
return htmlStr;
}

View File

@ -212,3 +212,23 @@ QPair<QString, QString> StringUtils::splitFirst(const QString& s, const QRegular
right = s.mid(end);
return qMakePair(left, right);
}
QString StringUtils::htmlListPatch(QString htmlStr)
{
int pos = htmlStr.indexOf("</ul>");
int imgPos;
while (pos != -1) {
pos = pos + 5; // 5 is the size of the </ul> tag
imgPos = htmlStr.indexOf("<img", pos);
if (imgPos == -1)
break; // no image after the tag
auto textBetween = htmlStr.mid(pos, imgPos - pos).trimmed(); // trim all white spaces
if (textBetween.isEmpty())
htmlStr.insert(pos, "<br>");
pos = htmlStr.indexOf("</ul>", pos);
}
return htmlStr;
}

View File

@ -85,4 +85,6 @@ QPair<QString, QString> splitFirst(const QString& s, const QString& sep, Qt::Cas
QPair<QString, QString> splitFirst(const QString& s, QChar sep, Qt::CaseSensitivity cs = Qt::CaseSensitive);
QPair<QString, QString> splitFirst(const QString& s, const QRegularExpression& re);
QString htmlListPatch(QString htmlStr);
} // namespace StringUtils