Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nyxrobotics authored and saitenntaisei committed Sep 4, 2024
1 parent c1643af commit 0de1eb8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
14 changes: 14 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ static void addFonts() {

int main(int argc, char *argv[])
{
// Set the platform plugin to xcb
qputenv("QT_QPA_PLATFORM", QByteArray("xcb"));
qputenv("QT_XCB_GL_INTEGRATION", QByteArray("glx"));
qputenv("LIBGL_ALWAYS_SOFTWARE", QByteArray("1"));
qputenv("QT_QUICK_BACKEND", QByteArray("software"));

// Set OpenGL format
QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setVersion(2, 0); // Set OpenGL version to 2.0
format.setProfile(QSurfaceFormat::NoProfile);
QSurfaceFormat::setDefaultFormat(format);

// Settings
QCoreApplication::setOrganizationName("VESC");
QCoreApplication::setOrganizationDomain("vesc-project.com");
Expand Down
25 changes: 25 additions & 0 deletions pages/pagevescpackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,31 @@ QString PageVescPackage::convertHtmlToMarkdown(const QString &html) {
// <br> and <br/> to newline
markdown.replace(QRegularExpression("<br\\s*/?>"), "\n");

// <h1> to <h6> to #
markdown.replace(QRegularExpression("<h1>(.*?)</h1>"), "# \\1\n");
markdown.replace(QRegularExpression("<h2>(.*?)</h2>"), "## \\1\n");
markdown.replace(QRegularExpression("<h3>(.*?)</h3>"), "### \\1\n");
markdown.replace(QRegularExpression("<h4>(.*?)</h4>"), "#### \\1\n");
markdown.replace(QRegularExpression("<h5>(.*?)</h5>"), "##### \\1\n");
markdown.replace(QRegularExpression("<h6>(.*?)</h6>"), "###### \\1\n");

// <ul> and <ol> to list
markdown.replace(QRegularExpression("<ul>"), "");
markdown.replace(QRegularExpression("<ol>"), "");
markdown.replace(QRegularExpression("<li>(.*?)</li>"), "- \\1\n");
markdown.replace(QRegularExpression("</ul>"), "");
markdown.replace(QRegularExpression("</ol>"), "");

// <a href="url">text</a> to [text](url)
markdown.replace(QRegularExpression("<a\\s+href=\"(.*?)\".*?>(.*?)</a>"), "[\\2](\\1)");

// <img src="url" alt="alt" /> to ![alt](url)
markdown.replace(QRegularExpression("<img\\s+src=\"(.*?)\".*?alt=\"(.*?)\".*?/?>"), "!\\[\\2\\](\\1)");

// <p> to newline and </p> to another newline
markdown.replace(QRegularExpression("<p>"), "");
markdown.replace(QRegularExpression("</p>"), "\n\n");

// Remove other HTML tags
markdown.remove(QRegularExpression("<[^>]*>"));

Expand Down
2 changes: 2 additions & 0 deletions widgets/helpdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ HelpDialog::HelpDialog(QString title, QString text, QWidget *parent) :
setWindowTitle(title);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
// For Qt 5.14.0 and above, set text as Markdown if it starts with '#'
if (text.trimmed().startsWith('#')) {
ui->textEdit->setMarkdown(text);
} else {
ui->textEdit->setText(text);
}
#else
// For Qt versions below 5.14.0, always set text as plain text
ui->textEdit->setText(text);
#endif

Expand Down

0 comments on commit 0de1eb8

Please sign in to comment.