From 4934ec2ea13177061fcd54a726f18b6d54f440e7 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 19 Jan 2021 18:36:47 +0100 Subject: [PATCH] Add syntax highlighting for open-ended quotes --- nw/config.py | 10 ++++++++++ nw/gui/dochighlight.py | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/nw/config.py b/nw/config.py index 61a173f1..ff149b91 100644 --- a/nw/config.py +++ b/nw/config.py @@ -142,6 +142,8 @@ class Config: self.bigDocLimit = 800 # Size threshold for heavy editor features in kilobytes self.highlightQuotes = True # Highlight text in quotes + self.allowOpenSQuote = False # Allow open-ended single quotes + self.allowOpenDQuote = True # Allow open-ended double quotes self.highlightEmph = True # Add colour to text emphasis ## User-Selected Symbols @@ -514,6 +516,12 @@ class Config: self.highlightQuotes = self._parseLine( cnfParse, cnfSec, "highlightquotes", self.CNF_BOOL, self.highlightQuotes ) + self.allowOpenSQuote = self._parseLine( + cnfParse, cnfSec, "allowopensquote", self.CNF_BOOL, self.allowOpenSQuote + ) + self.allowOpenDQuote = self._parseLine( + cnfParse, cnfSec, "allowopendquote", self.CNF_BOOL, self.allowOpenDQuote + ) self.highlightEmph = self._parseLine( cnfParse, cnfSec, "highlightemph", self.CNF_BOOL, self.highlightEmph ) @@ -645,6 +653,8 @@ class Config: cnfParse.set(cnfSec, "bigdoclimit", str(self.bigDocLimit)) cnfParse.set(cnfSec, "showfullpath", str(self.showFullPath)) cnfParse.set(cnfSec, "highlightquotes", str(self.highlightQuotes)) + cnfParse.set(cnfSec, "allowopensquote", str(self.allowOpenSQuote)) + cnfParse.set(cnfSec, "allowopendquote", str(self.allowOpenDQuote)) cnfParse.set(cnfSec, "highlightemph", str(self.highlightEmph)) ## Backup diff --git a/nw/gui/dochighlight.py b/nw/gui/dochighlight.py index 81a4956f..1550e783 100644 --- a/nw/gui/dochighlight.py +++ b/nw/gui/dochighlight.py @@ -151,18 +151,20 @@ class GuiDocHighlighter(QSyntaxHighlighter): fmtDC = self.mainConf.fmtDoubleQuotes[1] fmtSO = self.mainConf.fmtSingleQuotes[0] fmtSC = self.mainConf.fmtSingleQuotes[1] + dblEnd = "|$" if self.mainConf.allowOpenDQuote else "" + sngEnd = "|$" if self.mainConf.allowOpenSQuote else "" self.hRules.append(( "\\B\"(.*?)\"\\B", { 0 : self.hStyles["dialogue1"], } )) self.hRules.append(( - f"\\B{fmtDO:s}(.*?){fmtDC:s}\\B", { + f"(\\B{fmtDO})(.*?)({fmtDC}\\B{dblEnd})", { 0 : self.hStyles["dialogue2"], } )) self.hRules.append(( - f"\\B{fmtSO:s}(.*?){fmtSC:s}\\B", { + f"(\\B{fmtSO})(.*?)({fmtSC}\\B{sngEnd})", { 0 : self.hStyles["dialogue3"], } ))