Merge branch 'dev' into feature/build_gui

This commit is contained in:
Veronica Berglyd Olsen
2023-04-16 19:46:54 +02:00
20 changed files with 1058 additions and 976 deletions
+2 -2
View File
@@ -26,7 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import logging
from novelwriter.constants import nwKeyWords, nwLabels, nwHtmlUnicode
from novelwriter.core.tokenizer import Tokenizer
from novelwriter.core.tokenizer import Tokenizer, stripEscape
logger = logging.getLogger(__name__)
@@ -269,7 +269,7 @@ class ToHtml(Tokenizer):
parStyle = hStyle
for xPos, xLen, xFmt in reversed(tFormat):
tTemp = tTemp[:xPos] + htmlTags[xFmt] + tTemp[xPos+xLen:]
thisPar.append(tTemp.rstrip())
thisPar.append(stripEscape(tTemp.rstrip()))
elif tType == self.T_SYNOPSIS and self._doSynopsis:
tmpResult.append(self._formatSynopsis(tText))
+11 -17
View File
@@ -40,6 +40,17 @@ from novelwriter.constants import nwConst, nwRegEx, nwUnicode
logger = logging.getLogger(__name__)
def stripEscape(text):
"""Helper function to strip escaped markdown characters from
paragraph text.
"""
if "\\" in text:
# Checking first is slightly slower when there are escaped
# characters in the text, but significantly faster when not
return text.replace(r"\*", "*").replace(r"\~", "~").replace(r"\_", "_")
return text
class Tokenizer(ABC):
# In-Text Format
@@ -340,23 +351,6 @@ class Tokenizer(ABC):
return
def doPostProcessing(self):
"""Do some postprocessing. Overloaded by subclasses. This just
does the standard escaped characters.
"""
escapeDict = {
r"\*": "*",
r"\~": "~",
r"\_": "_",
}
escReplace = re.compile(
"|".join([re.escape(k) for k in escapeDict.keys()]), flags=re.DOTALL
)
self._theResult = escReplace.sub(
lambda x: escapeDict[x.group(0)], self._theResult
)
return
def tokenizeText(self):
"""Scan the text for either lines starting with specific
characters that indicate headers, comments, commands etc, or
+5 -4
View File
@@ -32,7 +32,7 @@ from zipfile import ZipFile
from datetime import datetime
from novelwriter.constants import nwKeyWords, nwLabels
from novelwriter.core.tokenizer import Tokenizer
from novelwriter.core.tokenizer import Tokenizer, stripEscape
logger = logging.getLogger(__name__)
@@ -1356,16 +1356,17 @@ class XMLParagraph:
return
def appendText(self, tText):
def appendText(self, text):
"""Append text to the XML element. We do this one character at
the time in order to be able to process line breaks, tabs and
spaces separately. Multiple spaces above one are concatenated
into a single tag, and must therefore be processed separately.
"""
text = stripEscape(text)
nSpaces = 0
self._rawTxt += tText
self._rawTxt += text
for c in tText:
for c in text:
if c == " ":
nSpaces += 1
continue