Merge branch 'release'
This commit is contained in:
@@ -37,7 +37,7 @@ from PyQt6.QtCore import QMargins, QSize
|
||||
from novelwriter import __version__
|
||||
from novelwriter.common import firstFloat, xmlElement, xmlSubElem
|
||||
from novelwriter.constants import nwHeadFmt, nwStyles
|
||||
from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt
|
||||
from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt, stripEscape
|
||||
from novelwriter.formats.tokenizer import Tokenizer
|
||||
from novelwriter.types import QtHexRgb
|
||||
|
||||
@@ -480,7 +480,7 @@ class ToDocX(Tokenizer):
|
||||
xmlSubElem(rPr, _wTag("color"), attrib={W_VAL: _docXCol(color)})
|
||||
|
||||
if isinstance(text, str):
|
||||
for segment in RX_TEXT.split(text):
|
||||
for segment in RX_TEXT.split(stripEscape(text)):
|
||||
if segment == "\n":
|
||||
xmlSubElem(xR, _wTag("br"))
|
||||
elif segment == "\t":
|
||||
|
||||
@@ -495,12 +495,10 @@ class Tokenizer(ABC):
|
||||
def doPreProcessing(self) -> None:
|
||||
"""Run pre-processing jobs before the text is tokenized."""
|
||||
# Process the user's auto-replace dictionary
|
||||
if autoReplace := self._project.data.autoReplace:
|
||||
repDict = {}
|
||||
for aKey, aVal in autoReplace.items():
|
||||
repDict[f"<{aKey}>"] = aVal
|
||||
xRep = re.compile("|".join([re.escape(k) for k in repDict.keys()]), flags=re.DOTALL)
|
||||
self._text = xRep.sub(lambda x: repDict[x.group(0)], self._text)
|
||||
if entry := self._project.data.autoReplace:
|
||||
replace = {f"<{k}>": v for k, v in entry.items()}
|
||||
rxRep = re.compile("|".join([re.escape(k) for k in replace]), flags=re.DOTALL)
|
||||
self._text = rxRep.sub(lambda x: replace[x.group(0)], self._text)
|
||||
return
|
||||
|
||||
def tokenizeText(self) -> None:
|
||||
|
||||
@@ -36,7 +36,7 @@ from PyQt6.QtPrintSupport import QPrinter
|
||||
|
||||
from novelwriter import __version__
|
||||
from novelwriter.constants import nwStyles, nwUnicode
|
||||
from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt
|
||||
from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt, stripEscape
|
||||
from novelwriter.formats.tokenizer import HEADINGS, Tokenizer
|
||||
from novelwriter.types import (
|
||||
QtAlignAbsolute, QtAlignCenter, QtAlignJustify, QtAlignLeft, QtAlignRight,
|
||||
@@ -343,7 +343,7 @@ class ToQTextDocument(Tokenizer):
|
||||
for pos, fmt, data in tFmt:
|
||||
|
||||
# Insert buffer with previous format
|
||||
cursor.insertText(temp[start:pos], cFmt)
|
||||
cursor.insertText(stripEscape(temp[start:pos]), cFmt)
|
||||
|
||||
# Construct next format
|
||||
if fmt == TextFmt.B_B:
|
||||
@@ -425,13 +425,12 @@ class ToQTextDocument(Tokenizer):
|
||||
if field := data.partition(":")[2]:
|
||||
self._usedFields.append((cursor.position(), field))
|
||||
cursor.insertText("0", cFmt)
|
||||
pass
|
||||
|
||||
# Move pos for next pass
|
||||
start = pos
|
||||
|
||||
# Insert whatever is left in the buffer
|
||||
cursor.insertText(temp[start:], cFmt)
|
||||
cursor.insertText(stripEscape(temp[start:]), cFmt)
|
||||
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user