Formatting and fixed img_pos allowed as negative

Signed-off-by: SabrePenguin <lknofczynski@gmail.com>
This commit is contained in:
SabrePenguin 2024-04-25 15:40:24 -04:00 committed by Trial97
parent 1d8ee37504
commit e201cad3f8
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318

View File

@ -24,16 +24,20 @@ QString markdownToHTML(const QString& markdown)
char* buffer = cmark_markdown_to_html(markdownData.constData(), markdownData.length(), CMARK_OPT_NOBREAKS | CMARK_OPT_UNSAFE);
QString htmlStr(buffer);
int first_pos = htmlStr.indexOf("</ul>");
int img_pos = 0;
while( first_pos != -1 )
{
img_pos = htmlStr.indexOf("<img", first_pos);
if ( img_pos - (first_pos + 5) < 3 && img_pos - (first_pos + 5) != -1)
htmlStr.insert(img_pos, "<br>");
first_pos = htmlStr.indexOf("</ul>", first_pos+5);
}
free(buffer);
// Insert a breakpoint between a </ul> and <img> tag as this can cause visual bugs
int first_pos = htmlStr.indexOf("</ul>");
int img_pos;
while (first_pos != -1) {
img_pos = htmlStr.indexOf("<img", first_pos);
if (img_pos - (first_pos + 5) < 3 && img_pos - (first_pos + 5) > -1) // 5 is the size of the </ul> tag
htmlStr.insert(img_pos, "<br>");
first_pos = htmlStr.indexOf("</ul>", first_pos + 5);
}
return htmlStr;
}