Skip to content

Commit

Permalink
Remove boundary condition in quote dialogue highlighting in most cases (
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Dec 8, 2024
1 parent cc5cd50 commit 3d858ed
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions novelwriter/text/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

from novelwriter import CONFIG
from novelwriter.common import compact, uniqueCompact
from novelwriter.constants import nwRegEx
from novelwriter.constants import nwRegEx, nwUnicode

AMBIGUOUS = (nwUnicode.U_APOS, nwUnicode.U_RSQUO)


class RegExPatterns:
Expand Down Expand Up @@ -92,11 +94,13 @@ def dialogStyle(self) -> re.Pattern | None:
if CONFIG.dialogStyle in (1, 3):
qO = CONFIG.fmtSQuoteOpen.strip()[:1]
qC = CONFIG.fmtSQuoteClose.strip()[:1]
rx.append(f"(?:\\B{qO}.*?(?:{qC}\\B{end}))")
qB = r"\B" if (qO == qC or qC in AMBIGUOUS) else ""
rx.append(f"(?:{qO}.*?(?:{qC}{qB}{end}))")
if CONFIG.dialogStyle in (2, 3):
qO = CONFIG.fmtDQuoteOpen.strip()[:1]
qC = CONFIG.fmtDQuoteClose.strip()[:1]
rx.append(f"(?:\\B{qO}.*?(?:{qC}\\B{end}))")
qB = r"\B" if (qO == qC or qC in AMBIGUOUS) else ""
rx.append(f"(?:{qO}.*?(?:{qC}{qB}{end}))")
return re.compile("|".join(rx), re.UNICODE)
return None

Expand All @@ -106,7 +110,8 @@ def altDialogStyle(self) -> re.Pattern | None:
if CONFIG.altDialogOpen and CONFIG.altDialogClose:
qO = re.escape(compact(CONFIG.altDialogOpen))
qC = re.escape(compact(CONFIG.altDialogClose))
return re.compile(f"\\B{qO}.*?{qC}\\B", re.UNICODE)
qB = r"\B" if (qO == qC or qC in AMBIGUOUS) else ""
return re.compile(f"{qO}.*?{qC}{qB}", re.UNICODE)
return None


Expand Down

0 comments on commit 3d858ed

Please sign in to comment.