Skip to content

Commit

Permalink
pbek/QOwnNotes#3222: Merge pull request #214 from DarienMC/feature/gd…
Browse files Browse the repository at this point in the history
…script_highlighting

Add GDScript Language Data for Markdown Highlighting.
  • Loading branch information
pbek authored Feb 1, 2025
2 parents 4864cb2 + 363c27c commit 1933a6d
Show file tree
Hide file tree
Showing 4 changed files with 1,294 additions and 2 deletions.
42 changes: 41 additions & 1 deletion markdownhighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ void MarkdownHighlighter::initCodeLangs() {
{QLatin1String("yaml"), MarkdownHighlighter::CodeYAML},
{QLatin1String("forth"), MarkdownHighlighter::CodeForth},
{QLatin1String("systemverilog"),
MarkdownHighlighter::CodeSystemVerilog}};
MarkdownHighlighter::CodeSystemVerilog},
{QLatin1String("gdscript"), MarkdownHighlighter::CodeGDScript},
};
}

/**
Expand Down Expand Up @@ -768,6 +770,7 @@ void MarkdownHighlighter::highlightSyntax(const QString &text) {
bool isYAML = false;
bool isMake = false;
bool isForth = false;
bool isGDScript = false;

QMultiHash<char, QLatin1String> keywords{};
QMultiHash<char, QLatin1String> others{};
Expand Down Expand Up @@ -921,6 +924,12 @@ void MarkdownHighlighter::highlightSyntax(const QString &text) {
case HighlighterState::CodeSystemVerilogComment:
loadSystemVerilogData(types, keywords, builtin, literals, others);
break;
case HighlighterState::CodeGDScript:
case HighlighterState::CodeGDScript + tildeOffset:
isGDScript = true;
loadGDScriptData(types, keywords, builtin, literals, others);
comment = QLatin1Char('#');
break;
default:
setFormat(0, textLen, _formats[CodeBlock]);
return;
Expand Down Expand Up @@ -1082,6 +1091,7 @@ void MarkdownHighlighter::highlightSyntax(const QString &text) {
if (isYAML) ymlHighlighter(text);
if (isMake) makeHighlighter(text);
if (isForth) forthHighlighter(text);
if (isGDScript) gdscriptHighlighter(text);
}

/**
Expand Down Expand Up @@ -1696,6 +1706,36 @@ void MarkdownHighlighter::forthHighlighter(const QString &text) {
}
}

/**
* @brief The GDScript highlighter
* @param text
* @details This function is responsible for GDScript highlighting.
* 1. Hightlight '$' NodePath constructs.
* 2. Highlight '%' UniqueNode constructs.
* 3. Highlight '@' annotations as `CodeOther`
*/
void MarkdownHighlighter::gdscriptHighlighter(const QString &text) {
if (text.isEmpty()) return;
const auto textLen = text.length();

for (int i = 0; i < textLen; ++i) {
// 1. Hightlight '$' NodePath constructs.
if (i + 1 <= textLen && text[i] == QLatin1Char('$')) {
/* TODO: Hightlight '$' NodePath constructs */
setFormat(i, 1, _formats[CodeNumLiteral]);
}
// 2. Highlight '%' UniqueNode constructs.
else if (i + 1 <= textLen && text[i] == QLatin1Char('%')) {
/* TODO: Highlight '%' UniqueNode constructs */
setFormat(i, 1, _formats[CodeNumLiteral]);
}
// 3. Hightlight '@' annotations symbol
else if (i + 1 <= textLen && text[i] == QLatin1Char('@')) {
setFormat(i, 1, _formats[CodeOther]);
}
}
}

/**
* Highlight multi-line frontmatter blocks
*
Expand Down
4 changes: 3 additions & 1 deletion markdownhighlighter.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class MarkdownHighlighter : public QSyntaxHighlighter {
CodeForthComment = 249,
CodeSystemVerilog = 250,
CodeSystemVerilogComment = 251,
CodeGDScript = 252,
};
Q_ENUM(HighlighterState)

Expand Down Expand Up @@ -331,9 +332,10 @@ class MarkdownHighlighter : public QSyntaxHighlighter {
void makeHighlighter(const QString &text);

void forthHighlighter(const QString &text);

void taggerScriptHighlighter(const QString &text);

void gdscriptHighlighter(const QString &text);

void addDirtyBlock(const QTextBlock &block);

void reHighlightDirtyBlocks();
Expand Down
Loading

0 comments on commit 1933a6d

Please sign in to comment.