Moved html patch to StringUtils
Signed-off-by: SabrePenguin <lknofczynski@gmail.com>
This commit is contained in:
parent
0c84d58915
commit
401de52f61
@ -27,21 +27,5 @@ QString markdownToHTML(const QString& markdown)
|
|||||||
|
|
||||||
free(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;
|
return htmlStr;
|
||||||
}
|
}
|
@ -212,3 +212,23 @@ QPair<QString, QString> StringUtils::splitFirst(const QString& s, const QRegular
|
|||||||
right = s.mid(end);
|
right = s.mid(end);
|
||||||
return qMakePair(left, right);
|
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;
|
||||||
|
}
|
@ -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, QChar sep, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
||||||
QPair<QString, QString> splitFirst(const QString& s, const QRegularExpression& re);
|
QPair<QString, QString> splitFirst(const QString& s, const QRegularExpression& re);
|
||||||
|
|
||||||
|
QString htmlListPatch(QString htmlStr);
|
||||||
|
|
||||||
} // namespace StringUtils
|
} // namespace StringUtils
|
||||||
|
Loading…
Reference in New Issue
Block a user