Merge pull request #2462 from Trial97/list-image-append-fix-backport

List image append fix backport
This commit is contained in:
Alexandru Ionut Tripon 2024-06-02 19:02:35 +03:00 committed by GitHub
commit 0cca84a335
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 56 additions and 18 deletions

View File

@ -212,3 +212,25 @@ QPair<QString, QString> StringUtils::splitFirst(const QString& s, const QRegular
right = s.mid(end);
return qMakePair(left, right);
}
static const QRegularExpression ulMatcher("<\\s*/\\s*ul\\s*>");
QString StringUtils::htmlListPatch(QString htmlStr)
{
int pos = htmlStr.indexOf(ulMatcher);
int imgPos;
while (pos != -1) {
pos = htmlStr.indexOf(">", pos) + 1; // Get the size of the </ul> tag. Add one for zeroeth index
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(ulMatcher, 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

View File

@ -38,6 +38,7 @@
#include "Application.h"
#include "BuildConfig.h"
#include "Markdown.h"
#include "StringUtils.h"
#include "ui_AboutDialog.h"
#include <net/NetJob.h>
@ -139,10 +140,10 @@ AboutDialog::AboutDialog(QWidget* parent) : QDialog(parent), ui(new Ui::AboutDia
setWindowTitle(tr("About %1").arg(launcherName));
QString chtml = getCreditsHtml();
ui->creditsText->setHtml(chtml);
ui->creditsText->setHtml(StringUtils::htmlListPatch(chtml));
QString lhtml = getLicenseHtml();
ui->licenseText->setHtml(lhtml);
ui->licenseText->setHtml(StringUtils::htmlListPatch(lhtml));
ui->urlLabel->setOpenExternalLinks(true);

View File

@ -22,6 +22,7 @@
#include <QTextEdit>
#include "FileSystem.h"
#include "Markdown.h"
#include "StringUtils.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/mod/ModFolderModel.h"
#include "modplatform/helpers/ExportToModList.h"
@ -143,10 +144,10 @@ void ExportToModListDialog::triggerImp()
case ExportToModList::CUSTOM:
return;
case ExportToModList::HTML:
ui->resultText->setHtml(txt);
ui->resultText->setHtml(StringUtils::htmlListPatch(txt));
break;
case ExportToModList::MARKDOWN:
ui->resultText->setHtml(markdownToHTML(txt));
ui->resultText->setHtml(StringUtils::htmlListPatch(markdownToHTML(txt)));
break;
case ExportToModList::PLAINTXT:
break;

View File

@ -3,6 +3,7 @@
#include "CustomMessageBox.h"
#include "ProgressDialog.h"
#include "ScrollMessageBox.h"
#include "StringUtils.h"
#include "minecraft/mod/tasks/GetModDependenciesTask.h"
#include "modplatform/ModIndex.h"
#include "modplatform/flame/FlameAPI.h"
@ -464,7 +465,7 @@ void ModUpdateDialog::appendMod(CheckUpdateTask::UpdatableMod const& info, QStri
break;
}
changelog_area->setHtml(text);
changelog_area->setHtml(StringUtils::htmlListPatch(text));
changelog_area->setOpenExternalLinks(true);
changelog_area->setLineWrapMode(QTextBrowser::LineWrapMode::WidgetWidth);
changelog_area->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);

View File

@ -25,6 +25,7 @@
#include "Application.h"
#include "BuildConfig.h"
#include "Markdown.h"
#include "StringUtils.h"
#include "ui_UpdateAvailableDialog.h"
UpdateAvailableDialog::UpdateAvailableDialog(const QString& currentVersion,
@ -43,7 +44,7 @@ UpdateAvailableDialog::UpdateAvailableDialog(const QString& currentVersion,
ui->icon->setPixmap(APPLICATION->getThemedIcon("checkupdate").pixmap(64));
auto releaseNotesHtml = markdownToHTML(releaseNotes);
ui->releaseNotes->setHtml(releaseNotesHtml);
ui->releaseNotes->setHtml(StringUtils::htmlListPatch(releaseNotesHtml));
ui->releaseNotes->setOpenExternalLinks(true);
connect(ui->skipButton, &QPushButton::clicked, this, [this]() {

View File

@ -20,6 +20,7 @@
#include "InstanceTask.h"
#include "Json.h"
#include "Markdown.h"
#include "StringUtils.h"
#include "modplatform/modrinth/ModrinthPackManifest.h"
@ -332,7 +333,7 @@ void ModrinthManagedPackPage::suggestVersion()
}
auto version = m_pack.versions.at(index);
ui->changelogTextBrowser->setHtml(markdownToHTML(version.changelog.toUtf8()));
ui->changelogTextBrowser->setHtml(StringUtils::htmlListPatch(markdownToHTML(version.changelog.toUtf8())));
ManagedPackPage::suggestVersion();
}
@ -420,7 +421,7 @@ void FlameManagedPackPage::parseManagedPack()
"Don't worry though, it will ask you to update this instance instead, so you'll not lose this instance!"
"</h4>");
ui->changelogTextBrowser->setHtml(message);
ui->changelogTextBrowser->setHtml(StringUtils::htmlListPatch(message));
return;
}
@ -502,7 +503,8 @@ void FlameManagedPackPage::suggestVersion()
}
auto version = m_pack.versions.at(index);
ui->changelogTextBrowser->setHtml(m_api.getModFileChangelog(m_inst->getManagedPackID().toInt(), version.fileId));
ui->changelogTextBrowser->setHtml(
StringUtils::htmlListPatch(m_api.getModFileChangelog(m_inst->getManagedPackID().toInt(), version.fileId)));
ManagedPackPage::suggestVersion();
}

View File

@ -45,6 +45,7 @@
#include "Markdown.h"
#include "StringUtils.h"
#include "ui/dialogs/ResourceDownloadDialog.h"
#include "ui/pages/modplatform/ResourceModel.h"
#include "ui/widgets/ProjectItem.h"
@ -234,8 +235,8 @@ void ResourcePage::updateUi()
text += "<hr>";
m_ui->packDescription->setHtml(
text + (current_pack->extraData.body.isEmpty() ? current_pack->description : markdownToHTML(current_pack->extraData.body)));
m_ui->packDescription->setHtml(StringUtils::htmlListPatch(
text + (current_pack->extraData.body.isEmpty() ? current_pack->description : markdownToHTML(current_pack->extraData.body))));
m_ui->packDescription->flush();
}

View File

@ -39,6 +39,7 @@
#include "ui_AtlPage.h"
#include "BuildConfig.h"
#include "StringUtils.h"
#include "AtlUserInteractionSupportImpl.h"
#include "modplatform/atlauncher/ATLPackInstallTask.h"
@ -144,7 +145,7 @@ void AtlPage::onSelectionChanged(QModelIndex first, [[maybe_unused]] QModelIndex
selected = filterModel->data(first, Qt::UserRole).value<ATLauncher::IndexedPack>();
ui->packDescription->setHtml(selected.description.replace("\n", "<br>"));
ui->packDescription->setHtml(StringUtils::htmlListPatch(selected.description.replace("\n", "<br>")));
for (const auto& version : selected.versions) {
ui->versionSelectionBox->addItem(version.version);

View File

@ -43,6 +43,7 @@
#include "FlameModel.h"
#include "InstanceImportTask.h"
#include "Json.h"
#include "StringUtils.h"
#include "modplatform/flame/FlameAPI.h"
#include "ui/dialogs/NewInstanceDialog.h"
#include "ui/widgets/ProjectItem.h"
@ -292,6 +293,6 @@ void FlamePage::updateUi()
text += "<hr>";
text += api.getModDescription(current.addonId).toUtf8();
ui->packDescription->setHtml(text + current.description);
ui->packDescription->setHtml(StringUtils::htmlListPatch(text + current.description));
ui->packDescription->flush();
}

View File

@ -35,6 +35,7 @@
*/
#include "Page.h"
#include "StringUtils.h"
#include "ui/widgets/ProjectItem.h"
#include "ui_Page.h"
@ -260,8 +261,9 @@ void Page::onPackSelectionChanged(Modpack* pack)
{
ui->versionSelectionBox->clear();
if (pack) {
currentModpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" + "<br>Minecraft " + pack->mcVersion + "<br>" + "<br>" +
pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>") + "</li></ul>");
currentModpackInfo->setHtml(StringUtils::htmlListPatch("Pack by <b>" + pack->author + "</b>" + "<br>Minecraft " + pack->mcVersion +
"<br>" + "<br>" + pack->description + "<ul><li>" +
pack->mods.replace(";", "</li><li>") + "</li></ul>"));
bool currentAdded = false;
for (int i = 0; i < pack->oldVersions.size(); i++) {

View File

@ -44,6 +44,7 @@
#include "InstanceImportTask.h"
#include "Json.h"
#include "Markdown.h"
#include "StringUtils.h"
#include "ui/widgets/ProjectItem.h"
@ -303,7 +304,7 @@ void ModrinthPage::updateUI()
text += markdownToHTML(current.extra.body.toUtf8());
ui->packDescription->setHtml(text + current.description);
ui->packDescription->setHtml(StringUtils::htmlListPatch(text + current.description));
ui->packDescription->flush();
}

View File

@ -44,6 +44,7 @@
#include "BuildConfig.h"
#include "Json.h"
#include "StringUtils.h"
#include "TechnicModel.h"
#include "modplatform/technic/SingleZipPackInstallTask.h"
#include "modplatform/technic/SolderPackInstallTask.h"
@ -233,7 +234,7 @@ void TechnicPage::metadataLoaded()
text += "<br><br>";
ui->packDescription->setHtml(text + current.description);
ui->packDescription->setHtml(StringUtils::htmlListPatch(text + current.description));
// Strip trailing forward-slashes from Solder URL's
if (current.isSolder) {

View File

@ -26,6 +26,7 @@
#include <QTextBrowser>
#include "Markdown.h"
#include "StringUtils.h"
SelectReleaseDialog::SelectReleaseDialog(const Version& current_version, const QList<GitHubRelease>& releases, QWidget* parent)
: QDialog(parent), m_releases(releases), m_currentVersion(current_version), ui(new Ui::SelectReleaseDialog)
@ -96,7 +97,7 @@ void SelectReleaseDialog::selectionChanged(QTreeWidgetItem* current, QTreeWidget
QString body = markdownToHTML(release.body.toUtf8());
m_selectedRelease = release;
ui->changelogTextBrowser->setHtml(body);
ui->changelogTextBrowser->setHtml(StringUtils::htmlListPatch(body));
}
SelectReleaseAssetDialog::SelectReleaseAssetDialog(const QList<GitHubReleaseAsset>& assets, QWidget* parent)