From f72e96662adf32c329ae77368d9a57bb4d7054d9 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 17 Apr 2025 17:25:33 +0200 Subject: [PATCH 1/2] Fix apostrophe and single quote ambiguity in dialogue (#2271) --- novelwriter/text/patterns.py | 4 ++-- tests/test_text/test_text_patterns.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/novelwriter/text/patterns.py b/novelwriter/text/patterns.py index d592b70c..a5d2b3e9 100644 --- a/novelwriter/text/patterns.py +++ b/novelwriter/text/patterns.py @@ -93,7 +93,7 @@ class RegExPatterns: if CONFIG.dialogStyle in (1, 3): qO = CONFIG.fmtSQuoteOpen.strip()[:1] qC = CONFIG.fmtSQuoteClose.strip()[:1] - if qO == qC: + if qO == qC or qC in self.AMBIGUOUS: rx.append(f"(?:\\B{qO}.+?{qC}\\B)") else: rx.append(f"(?:{qO}[^{qO}]+{qC})") @@ -102,7 +102,7 @@ class RegExPatterns: if CONFIG.dialogStyle in (2, 3): qO = CONFIG.fmtDQuoteOpen.strip()[:1] qC = CONFIG.fmtDQuoteClose.strip()[:1] - if qO == qC: + if qO == qC or qC in self.AMBIGUOUS: rx.append(f"(?:\\B{qO}.+?{qC}\\B)") else: rx.append(f"(?:{qO}[^{qO}]+{qC})") diff --git a/tests/test_text/test_text_patterns.py b/tests/test_text/test_text_patterns.py index ee938e10..e6a8b599 100644 --- a/tests/test_text/test_text_patterns.py +++ b/tests/test_text/test_text_patterns.py @@ -310,11 +310,11 @@ def testTextPatterns_DialogueStyle(): assert allMatches(regEx, 'one "two" three') == [] # Check with no whitespace, single quote - assert allMatches(regEx, "one\u2018two\u2019three") == [ - [("\u2018two\u2019", 3, 8)] - ] - assert allMatches(regEx, "one\u2018two\u2019 three") == [ - [("\u2018two\u2019", 3, 8)] + # The apostrophe ambiguity rule should kick in here + assert allMatches(regEx, "one\u2018two\u2019three") == [] + assert allMatches(regEx, "one\u2018two\u2019 three") == [] + assert allMatches(regEx, "one \u2018two\u02bc three\u2019 four") == [ + [("\u2018two\u02bc three\u2019", 4, 16)], ] # Check with no whitespace, double quote From da6cc88cd88de9da54dc869ec43c25bce37c093d Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 17 Apr 2025 17:32:23 +0200 Subject: [PATCH 2/2] Replace alternative apostrophes before spell checking --- novelwriter/gui/dochighlight.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/novelwriter/gui/dochighlight.py b/novelwriter/gui/dochighlight.py index c70d30d0..8103fd79 100644 --- a/novelwriter/gui/dochighlight.py +++ b/novelwriter/gui/dochighlight.py @@ -505,7 +505,7 @@ class TextBlockData(QTextBlockUserData): text = f"{text[:s]}{pad}{text[e:]}" self._metaData.append((s, e, res.group(0), "url")) - self._text = text + self._text = text.replace("\u02bc", "'") self._offset = offset return