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