From e66956046201417dbc02133f252ba3324006ac5f Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:57:35 +0200 Subject: [PATCH] Add syntax theme entry for shortcodes --- docs/source/int_customise.rst | 5 +++ novelwriter/assets/syntax/default_dark.conf | 1 + novelwriter/assets/syntax/default_light.conf | 1 + novelwriter/assets/syntax/grey_dark.conf | 1 + novelwriter/assets/syntax/grey_light.conf | 1 + novelwriter/assets/syntax/light_owl.conf | 1 + novelwriter/assets/syntax/night_owl.conf | 1 + novelwriter/assets/syntax/solarized_dark.conf | 1 + .../assets/syntax/solarized_light.conf | 1 + novelwriter/assets/syntax/tomorrow.conf | 1 + novelwriter/assets/syntax/tomorrow_night.conf | 1 + .../assets/syntax/tomorrow_night_blue.conf | 1 + .../assets/syntax/tomorrow_night_bright.conf | 1 + .../syntax/tomorrow_night_eighties.conf | 1 + novelwriter/gui/dochighlight.py | 36 +++++++++++-------- novelwriter/gui/theme.py | 2 ++ 16 files changed, 42 insertions(+), 14 deletions(-) diff --git a/docs/source/int_customise.rst b/docs/source/int_customise.rst index 9098db7d..1001c989 100644 --- a/docs/source/int_customise.rst +++ b/docs/source/int_customise.rst @@ -159,6 +159,7 @@ A syntax theme ``.conf`` file consists of the follwing settings: doublequotes = 0, 0, 0 singlequotes = 0, 0, 0 hidden = 0, 0, 0 + shortcode = 0, 0, 0 keyword = 0, 0, 0 value = 0, 0, 0 spellcheckline = 0, 0, 0 @@ -169,3 +170,7 @@ A syntax theme ``.conf`` file consists of the follwing settings: In the Main section, you must define at least the ``name`` setting. The Syntax colour values are RGB numbers on the format ``r, g, b`` where each is an integer from to 255. Omitted values default to black, except ``background`` which defaults to white, + +.. versionadded:: 2.2 + The `shortcode` syntax colour entry was added, so you need to update your custom themes if you + made any before version 2.2. diff --git a/novelwriter/assets/syntax/default_dark.conf b/novelwriter/assets/syntax/default_dark.conf index f015e5d6..77dc829e 100644 --- a/novelwriter/assets/syntax/default_dark.conf +++ b/novelwriter/assets/syntax/default_dark.conf @@ -17,6 +17,7 @@ straightquotes = 200, 46, 0 doublequotes = 184, 200, 0 singlequotes = 136, 200, 0 hidden = 150, 150, 150 +shortcode = 0, 155, 200 keyword = 200, 46, 0 value = 184, 200, 0 spellcheckline = 200, 46, 0 diff --git a/novelwriter/assets/syntax/default_light.conf b/novelwriter/assets/syntax/default_light.conf index 319fbda3..b4eab626 100644 --- a/novelwriter/assets/syntax/default_light.conf +++ b/novelwriter/assets/syntax/default_light.conf @@ -17,6 +17,7 @@ straightquotes = 200, 0, 0 doublequotes = 0, 0, 200 singlequotes = 0, 0, 200 hidden = 100, 100, 100 +shortcode = 0, 100, 0 keyword = 200, 50, 50 value = 50, 150, 50 spellcheckline = 200, 0, 0 diff --git a/novelwriter/assets/syntax/grey_dark.conf b/novelwriter/assets/syntax/grey_dark.conf index e579e8da..ed09963f 100644 --- a/novelwriter/assets/syntax/grey_dark.conf +++ b/novelwriter/assets/syntax/grey_dark.conf @@ -17,6 +17,7 @@ straightquotes = 200, 200, 200 doublequotes = 200, 200, 200 singlequotes = 200, 200, 200 hidden = 150, 150, 150 +shortcode = 225, 225, 225 keyword = 225, 225, 225 value = 200, 200, 200 spellcheckline = 200, 46, 0 diff --git a/novelwriter/assets/syntax/grey_light.conf b/novelwriter/assets/syntax/grey_light.conf index 32f9561c..e2ca0666 100644 --- a/novelwriter/assets/syntax/grey_light.conf +++ b/novelwriter/assets/syntax/grey_light.conf @@ -17,6 +17,7 @@ straightquotes = 20, 20, 20 doublequotes = 20, 20, 20 singlequotes = 20, 20, 20 hidden = 100, 100, 100 +shortcode = 0, 0, 0 keyword = 0, 0, 0 value = 20, 20, 20 spellcheckline = 200, 0, 0 diff --git a/novelwriter/assets/syntax/light_owl.conf b/novelwriter/assets/syntax/light_owl.conf index fdd0dc67..c42b3155 100644 --- a/novelwriter/assets/syntax/light_owl.conf +++ b/novelwriter/assets/syntax/light_owl.conf @@ -37,6 +37,7 @@ straightquotes = 222, 61, 58 doublequotes = 8, 145, 106 singlequotes = 255, 235, 149 hidden = 152, 159, 177 +shortcode = 40, 142, 215 keyword = 222, 61, 58 value = 150, 74, 193 spellcheckline = 222, 61, 58 diff --git a/novelwriter/assets/syntax/night_owl.conf b/novelwriter/assets/syntax/night_owl.conf index 59ad10da..2ee057e3 100644 --- a/novelwriter/assets/syntax/night_owl.conf +++ b/novelwriter/assets/syntax/night_owl.conf @@ -37,6 +37,7 @@ straightquotes = 247, 140, 108 doublequotes = 173, 219, 103 singlequotes = 255, 235, 149 hidden = 99, 119, 119 +shortcode = 130, 170, 255 keyword = 247, 140, 108 value = 199, 146, 234 spellcheckline = 247, 140, 108 diff --git a/novelwriter/assets/syntax/solarized_dark.conf b/novelwriter/assets/syntax/solarized_dark.conf index ec8a3d8d..ef34ddf4 100644 --- a/novelwriter/assets/syntax/solarized_dark.conf +++ b/novelwriter/assets/syntax/solarized_dark.conf @@ -17,6 +17,7 @@ straightquotes = 211, 54, 130 doublequotes = 42, 161, 152 singlequotes = 42, 161, 152 hidden = 147, 161, 161 +shortcode = 147, 161, 161 keyword = 133, 153, 0 value = 203, 75, 22 spellcheckline = 203, 75, 22 diff --git a/novelwriter/assets/syntax/solarized_light.conf b/novelwriter/assets/syntax/solarized_light.conf index 319a084c..21a31ade 100644 --- a/novelwriter/assets/syntax/solarized_light.conf +++ b/novelwriter/assets/syntax/solarized_light.conf @@ -17,6 +17,7 @@ straightquotes = 211, 54, 130 doublequotes = 42, 161, 152 singlequotes = 42, 161, 152 hidden = 88, 110, 117 +shortcode = 88, 110, 117 keyword = 133, 153, 0 value = 203, 75, 22 spellcheckline = 203, 75, 22 diff --git a/novelwriter/assets/syntax/tomorrow.conf b/novelwriter/assets/syntax/tomorrow.conf index 6333f06e..20430fcd 100644 --- a/novelwriter/assets/syntax/tomorrow.conf +++ b/novelwriter/assets/syntax/tomorrow.conf @@ -37,6 +37,7 @@ straightquotes = 240, 40, 41 doublequotes = 113, 140, 0 singlequotes = 234, 183, 0 hidden = 142, 144, 140 +shortcode = 66, 113, 174 keyword = 240, 40, 41 value = 137, 89, 168 spellcheckline = 240, 40, 41 diff --git a/novelwriter/assets/syntax/tomorrow_night.conf b/novelwriter/assets/syntax/tomorrow_night.conf index 2a4e8751..97c217df 100644 --- a/novelwriter/assets/syntax/tomorrow_night.conf +++ b/novelwriter/assets/syntax/tomorrow_night.conf @@ -37,6 +37,7 @@ straightquotes = 204, 102, 102 doublequotes = 181, 189, 104 singlequotes = 240, 198, 116 hidden = 150, 152, 150 +shortcode = 129, 162, 190 keyword = 204, 102, 102 value = 178, 148, 187 spellcheckline = 204, 102, 102 diff --git a/novelwriter/assets/syntax/tomorrow_night_blue.conf b/novelwriter/assets/syntax/tomorrow_night_blue.conf index 1a8459bf..18c930e7 100644 --- a/novelwriter/assets/syntax/tomorrow_night_blue.conf +++ b/novelwriter/assets/syntax/tomorrow_night_blue.conf @@ -37,6 +37,7 @@ straightquotes = 255, 157, 164 doublequotes = 209, 241, 169 singlequotes = 255, 238, 173 hidden = 114, 133, 183 +shortcode = 187, 218, 255 keyword = 255, 157, 164 value = 235, 187, 255 spellcheckline = 255, 157, 164 diff --git a/novelwriter/assets/syntax/tomorrow_night_bright.conf b/novelwriter/assets/syntax/tomorrow_night_bright.conf index c5bccc99..b7bf5658 100644 --- a/novelwriter/assets/syntax/tomorrow_night_bright.conf +++ b/novelwriter/assets/syntax/tomorrow_night_bright.conf @@ -37,6 +37,7 @@ straightquotes = 213, 78, 83 doublequotes = 185, 202, 74 singlequotes = 231, 197, 71 hidden = 150, 152, 150 +shortcode = 122, 166, 218 keyword = 213, 78, 83 value = 195, 151, 216 spellcheckline = 213, 78, 83 diff --git a/novelwriter/assets/syntax/tomorrow_night_eighties.conf b/novelwriter/assets/syntax/tomorrow_night_eighties.conf index c7314f17..29dbecc5 100644 --- a/novelwriter/assets/syntax/tomorrow_night_eighties.conf +++ b/novelwriter/assets/syntax/tomorrow_night_eighties.conf @@ -37,6 +37,7 @@ straightquotes = 242, 119, 122 doublequotes = 153, 204, 153 singlequotes = 255, 204, 102 hidden = 153, 153, 153 +shortcode = 102, 153, 204 keyword = 242, 119, 122 value = 204, 153, 204 spellcheckline = 242, 119, 122 diff --git a/novelwriter/gui/dochighlight.py b/novelwriter/gui/dochighlight.py index 482e2612..6a77f267 100644 --- a/novelwriter/gui/dochighlight.py +++ b/novelwriter/gui/dochighlight.py @@ -39,7 +39,7 @@ from novelwriter.constants import nwRegEx, nwUnicode logger = logging.getLogger(__name__) -SPELLRX = QRegularExpression(r"\b[^\s\-\+\/–—\[\]]+\b") +SPELLRX = QRegularExpression(r"\b[^\s\-\+\/–—\[\]:]+\b") SPELLRX.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption) @@ -69,6 +69,7 @@ class GuiDocHighlighter(QSyntaxHighlighter): self._colDialD = QColor(0, 0, 0) self._colDialS = QColor(0, 0, 0) self._colHidden = QColor(0, 0, 0) + self._colCode = QColor(0, 0, 0) self._colKey = QColor(0, 0, 0) self._colVal = QColor(0, 0, 0) self._colSpell = QColor(0, 0, 0) @@ -95,6 +96,7 @@ class GuiDocHighlighter(QSyntaxHighlighter): self._colDialD = QColor(*SHARED.theme.colDialD) self._colDialS = QColor(*SHARED.theme.colDialS) self._colHidden = QColor(*SHARED.theme.colHidden) + self._colCode = QColor(*SHARED.theme.colCode) self._colKey = QColor(*SHARED.theme.colKey) self._colVal = QColor(*SHARED.theme.colVal) self._colSpell = QColor(*SHARED.theme.colSpell) @@ -127,6 +129,7 @@ class GuiDocHighlighter(QSyntaxHighlighter): "dialogue3": self._makeFormat(self._colDialS), "replace": self._makeFormat(self._colRepTag), "hidden": self._makeFormat(self._colHidden), + "code": self._makeFormat(self._colCode), "keyword": self._makeFormat(self._colKey), "modifier": self._makeFormat(self._colMod), "value": self._makeFormat(self._colVal, "underline"), @@ -205,14 +208,19 @@ class GuiDocHighlighter(QSyntaxHighlighter): } )) - # In-Text Command + # Shortcodes self._hRules.append(( - nwRegEx.FMT_IN, { - 1: self._hStyles["keyword"], - 2: self._hStyles["keyword"], - 3: self._hStyles["keyword"], - 4: self._hStyles["codevalue"], - 5: self._hStyles["keyword"], + nwRegEx.FMT_SC, { + 1: self._hStyles["code"], + } + )) + + # Shortcodes w/Value + self._hRules.append(( + nwRegEx.FMT_SV, { + 1: self._hStyles["code"], + 2: self._hStyles["codevalue"], + 3: self._hStyles["code"], } )) @@ -358,17 +366,17 @@ class GuiDocHighlighter(QSyntaxHighlighter): else: # Text Paragraph if text.startswith("["): # Special Command - sText = text.rstrip() - if sText in ("[NEWPAGE]", "[NEW PAGE]", "[VSPACE]"): - self.setFormat(0, len(text), self._hStyles["keyword"]) + sText = text.rstrip().lower() + if sText in ("[newpage]", "[new page]", "[vspace]"): + self.setFormat(0, len(text), self._hStyles["code"]) return - elif sText.startswith("[VSPACE:") and sText.endswith("]"): + elif sText.startswith("[vspace:") and sText.endswith("]"): tLen = len(sText) tVal = checkInt(sText[8:-1], 0) cVal = "codevalue" if tVal > 0 else "codeinval" - self.setFormat(0, 8, self._hStyles["keyword"]) + self.setFormat(0, 8, self._hStyles["code"]) self.setFormat(8, tLen-9, self._hStyles[cVal]) - self.setFormat(tLen-1, tLen, self._hStyles["keyword"]) + self.setFormat(tLen-1, tLen, self._hStyles["code"]) return # Regular Text diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index a91d9ae1..da8f1be4 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -97,6 +97,7 @@ class GuiTheme: self.colDialD = [0, 0, 0] self.colDialS = [0, 0, 0] self.colHidden = [0, 0, 0] + self.colCode = [0, 0, 0] self.colKey = [0, 0, 0] self.colVal = [0, 0, 0] self.colSpell = [0, 0, 0] @@ -316,6 +317,7 @@ class GuiTheme: self.colDialD = self._parseColour(confParser, cnfSec, "doublequotes") self.colDialS = self._parseColour(confParser, cnfSec, "singlequotes") self.colHidden = self._parseColour(confParser, cnfSec, "hidden") + self.colCode = self._parseColour(confParser, cnfSec, "shortcode") self.colKey = self._parseColour(confParser, cnfSec, "keyword") self.colVal = self._parseColour(confParser, cnfSec, "value") self.colSpell = self._parseColour(confParser, cnfSec, "spellcheckline")