fixed issue of text color changing for code blocks in light mode (#1299)

This commit is contained in:
Lakshay Kansal 2023-07-31 12:18:19 -04:00 committed by GitHub
parent 55f96aacc6
commit 3d2db76070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,8 @@ enum Language {
Php
};
static QColor defaultColor = "#d1d5db"; // white
static QColor keywordColor = "#2e95d3"; // blue
static QColor functionColor = "#f22c3d"; // red
static QColor functionCallColor = "#e9950c"; // orange
@ -91,6 +93,12 @@ static QVector<HighlightingRule> pythonHighlightingRules()
HighlightingRule rule;
QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);
QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
@ -151,6 +159,12 @@ static QVector<HighlightingRule> csharpHighlightingRules()
HighlightingRule rule;
QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);
// Function call highlighting
QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
@ -219,6 +233,12 @@ static QVector<HighlightingRule> cppHighlightingRules()
HighlightingRule rule;
QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);
QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
@ -297,6 +317,12 @@ static QVector<HighlightingRule> typescriptHighlightingRules()
HighlightingRule rule;
QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);
QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
@ -381,6 +407,12 @@ static QVector<HighlightingRule> javaHighlightingRules()
HighlightingRule rule;
QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);
QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
@ -450,6 +482,12 @@ static QVector<HighlightingRule> goHighlightingRules()
HighlightingRule rule;
QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);
QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
@ -515,6 +553,12 @@ static QVector<HighlightingRule> bashHighlightingRules()
HighlightingRule rule;
QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);
QTextCharFormat commandFormat;
commandFormat.setForeground(commandColor);
QStringList commandPatterns = {
@ -582,6 +626,12 @@ static QVector<HighlightingRule> latexHighlightingRules()
HighlightingRule rule;
QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);
QTextCharFormat commandFormat;
commandFormat.setForeground(commandColor); // commandColor needs to be set to your liking
rule.pattern = QRegularExpression("\\\\[A-Za-z]+"); // Pattern for LaTeX commands
@ -604,6 +654,12 @@ static QVector<HighlightingRule> htmlHighlightingRules()
HighlightingRule rule;
QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);
QTextCharFormat attributeNameFormat;
attributeNameFormat.setForeground(attributeNameColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*=");
@ -644,6 +700,12 @@ static QVector<HighlightingRule> phpHighlightingRules()
HighlightingRule rule;
QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);
QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
@ -711,6 +773,12 @@ static QVector<HighlightingRule> jsonHighlightingRules()
HighlightingRule rule;
QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);
// Key string rule
QTextCharFormat keyFormat;
keyFormat.setForeground(keyColor); // Assuming keyColor is defined