fix(StatusSyntaxHighlighter): Updated regex and text formatting

Closes https://github.com/status-im/status-desktop/issues/6030
This commit is contained in:
Alexandra Betouni 2022-06-10 18:50:49 +03:00 committed by Michał
parent e666ccf1ad
commit 63b6e8c885
1 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,7 @@
#include "DOtherSide/DOtherSideStatusSyntaxHighlighter.h" #include "DOtherSide/DOtherSideStatusSyntaxHighlighter.h"
#include <QQuickTextDocument> #include <QQuickTextDocument>
#include <Qt>
#include <QBrush>
StatusSyntaxHighlighter::StatusSyntaxHighlighter(QTextDocument *parent) StatusSyntaxHighlighter::StatusSyntaxHighlighter(QTextDocument *parent)
: QSyntaxHighlighter(parent) : QSyntaxHighlighter(parent)
@ -8,20 +10,21 @@ StatusSyntaxHighlighter::StatusSyntaxHighlighter(QTextDocument *parent)
//BOLD //BOLD
singlelineBoldFormat.setFontWeight(QFont::Bold); singlelineBoldFormat.setFontWeight(QFont::Bold);
rule.pattern = QRegularExpression(QStringLiteral("\\*\\*(.*?)\\*\\*")); rule.pattern = QRegularExpression(QStringLiteral("(\\*\\*(.*?)\\*\\*)|(\\_\\_(.*?)\\_\\_)"));
rule.format = singlelineBoldFormat; rule.format = singlelineBoldFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
//BOLD //BOLD
//ITALIC //ITALIC
singleLineItalicFormat.setFontItalic(true); singleLineItalicFormat.setFontItalic(true);
rule.pattern = QRegularExpression(QStringLiteral("\\*(.*?)\\*")); rule.pattern = QRegularExpression(QStringLiteral("(\\*(.*?)\\*)|(\\_(.*?)\\_)"));
rule.format = singleLineItalicFormat; rule.format = singleLineItalicFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
//ITALIC //ITALIC
//CODE //CODE
singlelineCodeBlockFormat.setFontFamily("Roboto Mono"); singlelineCodeBlockFormat.setFontFamily("Roboto Mono");
singlelineCodeBlockFormat.setBackground(QBrush(Qt::lightGray));
rule.pattern = QRegularExpression(QStringLiteral("\\`(.*?)\\`")); rule.pattern = QRegularExpression(QStringLiteral("\\`(.*?)\\`"));
rule.format = singlelineCodeBlockFormat; rule.format = singlelineCodeBlockFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
@ -29,13 +32,14 @@ StatusSyntaxHighlighter::StatusSyntaxHighlighter(QTextDocument *parent)
//STRIKETHROUGH //STRIKETHROUGH
singleLineStrikeThroughFormat.setFontStrikeOut(true); singleLineStrikeThroughFormat.setFontStrikeOut(true);
rule.pattern = QRegularExpression(QStringLiteral("\\~+(.*?)\\~+")); rule.pattern = QRegularExpression(QStringLiteral("\\~\\~(.*?)\\~\\~"));
rule.format = singleLineStrikeThroughFormat; rule.format = singleLineStrikeThroughFormat;
highlightingRules.append(rule); highlightingRules.append(rule);
//STRIKETHROUGH //STRIKETHROUGH
//CODE BLOCK //CODE BLOCK
multiLineCodeBlockFormat.setFontFamily("Roboto Mono"); multiLineCodeBlockFormat.setFontFamily("Roboto Mono");
multiLineCodeBlockFormat.setBackground(QBrush(Qt::lightGray));
rule.pattern = QRegularExpression(QStringLiteral("\\`\\`\\`(.*?)\\`\\`\\`")); rule.pattern = QRegularExpression(QStringLiteral("\\`\\`\\`(.*?)\\`\\`\\`"));
rule.format = multiLineCodeBlockFormat; rule.format = multiLineCodeBlockFormat;
highlightingRules.append(rule); highlightingRules.append(rule);