Simplify core variables in tokenizer

This commit is contained in:
Veronica Berglyd Olsen
2023-06-06 00:03:46 +02:00
parent 67f1dd6677
commit 850ee73ed4
8 changed files with 295 additions and 297 deletions
+7 -7
View File
@@ -109,7 +109,7 @@ class ToHtml(Tokenizer):
characters into their respective HTML entities. characters into their respective HTML entities.
""" """
super().doPreProcessing() super().doPreProcessing()
self._theText = self._theText.translate(self._trMap) self._text = self._text.translate(self._trMap)
return return
def doConvert(self): def doConvert(self):
@@ -149,13 +149,13 @@ class ToHtml(Tokenizer):
h3 = "h3" h3 = "h3"
h4 = "h4" h4 = "h4"
self._theResult = "" self._result = ""
thisPar = [] thisPar = []
parStyle = None parStyle = None
tmpResult = [] tmpResult = []
for tType, tLine, tText, tFormat, tStyle in self._theTokens: for tType, tLine, tText, tFormat, tStyle in self._tokens:
# Replace < and > with HTML entities # Replace < and > with HTML entities
if tFormat: if tFormat:
@@ -282,11 +282,11 @@ class ToHtml(Tokenizer):
tTemp = f"<p{hStyle}>{self._formatKeywords(tText)}</p>\n" tTemp = f"<p{hStyle}>{self._formatKeywords(tText)}</p>\n"
tmpResult.append(tTemp) tmpResult.append(tTemp)
self._theResult = "".join(tmpResult) self._result = "".join(tmpResult)
tmpResult = [] tmpResult = []
if self._genMode != self.M_PREVIEW: if self._genMode != self.M_PREVIEW:
self._fullHTML.append(self._theResult) self._fullHTML.append(self._result)
return return
@@ -316,7 +316,7 @@ class ToHtml(Tokenizer):
"</body>\n" "</body>\n"
"</html>\n" "</html>\n"
).format( ).format(
projTitle=self.theProject.data.name, projTitle=self._project.data.name,
htmlStyle="\n".join(theStyle), htmlStyle="\n".join(theStyle),
bodyText=bodyText, bodyText=bodyText,
) )
@@ -452,7 +452,7 @@ class ToHtml(Tokenizer):
def _formatKeywords(self, tText): def _formatKeywords(self, tText):
"""Apply HTML formatting to keywords. """Apply HTML formatting to keywords.
""" """
isValid, theBits, _ = self.theProject.index.scanThis("@"+tText) isValid, theBits, _ = self._project.index.scanThis("@"+tText)
if not isValid or not theBits: if not isValid or not theBits:
return "" return ""
+65 -67
View File
@@ -91,16 +91,15 @@ class Tokenizer(ABC):
A_IND_L = 0x0100 # Left indentation A_IND_L = 0x0100 # Left indentation
A_IND_R = 0x0200 # Right indentation A_IND_R = 0x0200 # Right indentation
def __init__(self, theProject): def __init__(self, project: NWProject):
self.theProject = theProject self._project = project
# Data Variables # Data Variables
self._theText = "" # The raw text to be tokenized self._text = "" # The raw text to be tokenized
self._theHandle = None # The handle associated with the text self._nwItem = None # The NWItem associated with the handle
self._theItem = None # The NWItem associated with the handle self._tokens = [] # The list of the processed tokens
self._theTokens = [] # The list of the processed tokens self._result = "" # The result of the last document
self._theResult = "" # The result of the last document
self._keepMarkdown = False # Whether to keep the markdown text self._keepMarkdown = False # Whether to keep the markdown text
self._theMarkdown = [] # The result novelWriter markdown of all documents self._theMarkdown = [] # The result novelWriter markdown of all documents
@@ -139,7 +138,7 @@ class Tokenizer(ABC):
self._linkHeaders = False # Add an anchor before headers self._linkHeaders = False # Add an anchor before headers
# Instance Variables # Instance Variables
self._hFormatter = HeadingFormatter(self.theProject) self._hFormatter = HeadingFormatter(self._project)
self._firstScene = False # Flag to indicate that the first scene of the chapter self._firstScene = False # Flag to indicate that the first scene of the chapter
# This File # This File
@@ -152,7 +151,7 @@ class Tokenizer(ABC):
self._errData = [] self._errData = []
# Function Mapping # Function Mapping
self._localLookup = self.theProject.localLookup self._localLookup = self._project.localLookup
self.tr = partial(QCoreApplication.translate, "Tokenizer") self.tr = partial(QCoreApplication.translate, "Tokenizer")
# Cached Translations # Cached Translations
@@ -166,7 +165,7 @@ class Tokenizer(ABC):
@property @property
def theResult(self): def theResult(self):
return self._theResult return self._result
@property @property
def theMarkdown(self): def theMarkdown(self):
@@ -283,7 +282,7 @@ class Tokenizer(ABC):
def addRootHeading(self, theHandle): def addRootHeading(self, theHandle):
"""Add a heading at the start of a new root folder. """Add a heading at the start of a new root folder.
""" """
if not self.theProject.tree.checkType(theHandle, nwItemType.ROOT): if not self._project.tree.checkType(theHandle, nwItemType.ROOT):
return False return False
if self._isFirst: if self._isFirst:
@@ -292,11 +291,11 @@ class Tokenizer(ABC):
else: else:
textAlign = self.A_PBB | self.A_CENTRE textAlign = self.A_PBB | self.A_CENTRE
theItem = self.theProject.tree[theHandle] theItem = self._project.tree[theHandle]
locNotes = self._localLookup("Notes") locNotes = self._localLookup("Notes")
theTitle = f"{locNotes}: {theItem.itemName}" theTitle = f"{locNotes}: {theItem.itemName}"
self._theTokens = [] self._tokens = []
self._theTokens.append(( self._tokens.append((
self.T_TITLE, 0, theTitle, None, textAlign self.T_TITLE, 0, theTitle, None, textAlign
)) ))
if self._keepMarkdown: if self._keepMarkdown:
@@ -308,27 +307,26 @@ class Tokenizer(ABC):
"""Set the text for the tokenizer from a handle. If theText is """Set the text for the tokenizer from a handle. If theText is
not set, load it from the file. not set, load it from the file.
""" """
self._theHandle = theHandle self._nwItem = self._project.tree[theHandle]
self._theItem = self.theProject.tree[theHandle] if self._nwItem is None:
if self._theItem is None:
return False return False
if theText is None: if theText is None:
theText = self.theProject.storage.getDocument(theHandle).readDocument() or "" theText = self._project.storage.getDocument(theHandle).readDocument() or ""
self._theText = theText self._text = theText
docSize = len(self._theText) docSize = len(self._text)
if docSize > nwConst.MAX_DOCSIZE: if docSize > nwConst.MAX_DOCSIZE:
errVal = self.tr("Document '{0}' is too big ({1} MB). Skipping.").format( errVal = self.tr("Document '{0}' is too big ({1} MB). Skipping.").format(
self._theItem.itemName, f"{docSize/1.0e6:.2f}" self._nwItem.itemName, f"{docSize/1.0e6:.2f}"
) )
self._theText = "# {0}\n\n{1}\n\n".format(self.tr("ERROR"), errVal) self._text = "# {0}\n\n{1}\n\n".format(self.tr("ERROR"), errVal)
self._errData.append(errVal) self._errData.append(errVal)
self._isNone = self._theItem.itemLayout == nwItemLayout.NO_LAYOUT self._isNone = self._nwItem.itemLayout == nwItemLayout.NO_LAYOUT
self._isNovel = self._theItem.itemLayout == nwItemLayout.DOCUMENT self._isNovel = self._nwItem.itemLayout == nwItemLayout.DOCUMENT
self._isNote = self._theItem.itemLayout == nwItemLayout.NOTE self._isNote = self._nwItem.itemLayout == nwItemLayout.NOTE
return True return True
@@ -336,17 +334,17 @@ class Tokenizer(ABC):
"""Run trough the various replace doctionaries. """Run trough the various replace doctionaries.
""" """
# Process the user's auto-replace dictionary # Process the user's auto-replace dictionary
autoReplace = self.theProject.data.autoReplace autoReplace = self._project.data.autoReplace
if len(autoReplace) > 0: if len(autoReplace) > 0:
repDict = {} repDict = {}
for aKey, aVal in autoReplace.items(): for aKey, aVal in autoReplace.items():
repDict[f"<{aKey}>"] = aVal repDict[f"<{aKey}>"] = aVal
xRep = re.compile("|".join([re.escape(k) for k in repDict.keys()]), flags=re.DOTALL) xRep = re.compile("|".join([re.escape(k) for k in repDict.keys()]), flags=re.DOTALL)
self._theText = xRep.sub(lambda x: repDict[x.group(0)], self._theText) self._text = xRep.sub(lambda x: repDict[x.group(0)], self._text)
# Process the character translation map # Process the character translation map
trDict = {nwUnicode.U_MAPOSS: nwUnicode.U_RSQUO} trDict = {nwUnicode.U_MAPOSS: nwUnicode.U_RSQUO}
self._theText = self._theText.translate(str.maketrans(trDict)) self._text = self._text.translate(str.maketrans(trDict))
return return
@@ -372,17 +370,17 @@ class Tokenizer(ABC):
(QRegularExpression(nwRegEx.FMT_ST), [None, self.FMT_D_B, None, self.FMT_D_E]), (QRegularExpression(nwRegEx.FMT_ST), [None, self.FMT_D_B, None, self.FMT_D_E]),
] ]
self._theTokens = [] self._tokens = []
tmpMarkdown = [] tmpMarkdown = []
nLine = 0 nLine = 0
breakNext = False breakNext = False
for aLine in self._theText.splitlines(): for aLine in self._text.splitlines():
nLine += 1 nLine += 1
sLine = aLine.strip() sLine = aLine.strip()
# Check for blank lines # Check for blank lines
if len(sLine) == 0: if len(sLine) == 0:
self._theTokens.append(( self._tokens.append((
self.T_EMPTY, nLine, "", None, self.A_NONE self.T_EMPTY, nLine, "", None, self.A_NONE
)) ))
if self._keepMarkdown: if self._keepMarkdown:
@@ -407,7 +405,7 @@ class Tokenizer(ABC):
continue continue
elif sLine == "[VSPACE]": elif sLine == "[VSPACE]":
self._theTokens.append( self._tokens.append(
(self.T_SKIP, nLine, "", None, sAlign) (self.T_SKIP, nLine, "", None, sAlign)
) )
continue continue
@@ -415,11 +413,11 @@ class Tokenizer(ABC):
elif sLine.startswith("[VSPACE:") and sLine.endswith("]"): elif sLine.startswith("[VSPACE:") and sLine.endswith("]"):
nSkip = checkInt(sLine[8:-1], 0) nSkip = checkInt(sLine[8:-1], 0)
if nSkip >= 1: if nSkip >= 1:
self._theTokens.append( self._tokens.append(
(self.T_SKIP, nLine, "", None, sAlign) (self.T_SKIP, nLine, "", None, sAlign)
) )
if nSkip > 1: if nSkip > 1:
self._theTokens += (nSkip - 1) * [ self._tokens += (nSkip - 1) * [
(self.T_SKIP, nLine, "", None, self.A_NONE) (self.T_SKIP, nLine, "", None, self.A_NONE)
] ]
continue continue
@@ -428,20 +426,20 @@ class Tokenizer(ABC):
cLine = aLine[1:].lstrip() cLine = aLine[1:].lstrip()
synTag = cLine[:9].lower() synTag = cLine[:9].lower()
if synTag == "synopsis:": if synTag == "synopsis:":
self._theTokens.append(( self._tokens.append((
self.T_SYNOPSIS, nLine, cLine[9:].strip(), None, sAlign self.T_SYNOPSIS, nLine, cLine[9:].strip(), None, sAlign
)) ))
if self._doSynopsis and self._keepMarkdown: if self._doSynopsis and self._keepMarkdown:
tmpMarkdown.append("%s\n" % aLine) tmpMarkdown.append("%s\n" % aLine)
else: else:
self._theTokens.append(( self._tokens.append((
self.T_COMMENT, nLine, aLine[1:].strip(), None, sAlign self.T_COMMENT, nLine, aLine[1:].strip(), None, sAlign
)) ))
if self._doComments and self._keepMarkdown: if self._doComments and self._keepMarkdown:
tmpMarkdown.append("%s\n" % aLine) tmpMarkdown.append("%s\n" % aLine)
elif aLine[0] == "@": elif aLine[0] == "@":
self._theTokens.append(( self._tokens.append((
self.T_KEYWORD, nLine, aLine[1:].strip(), None, sAlign self.T_KEYWORD, nLine, aLine[1:].strip(), None, sAlign
)) ))
if self._doKeywords and self._keepMarkdown: if self._doKeywords and self._keepMarkdown:
@@ -452,7 +450,7 @@ class Tokenizer(ABC):
sAlign |= self.A_CENTRE sAlign |= self.A_CENTRE
sAlign |= self.A_PBB sAlign |= self.A_PBB
self._theTokens.append(( self._tokens.append((
self.T_HEAD1, nLine, aLine[2:].strip(), None, sAlign self.T_HEAD1, nLine, aLine[2:].strip(), None, sAlign
)) ))
if self._keepMarkdown: if self._keepMarkdown:
@@ -462,21 +460,21 @@ class Tokenizer(ABC):
if self._isNovel: if self._isNovel:
sAlign |= self.A_PBB sAlign |= self.A_PBB
self._theTokens.append(( self._tokens.append((
self.T_HEAD2, nLine, aLine[3:].strip(), None, sAlign self.T_HEAD2, nLine, aLine[3:].strip(), None, sAlign
)) ))
if self._keepMarkdown: if self._keepMarkdown:
tmpMarkdown.append("%s\n" % aLine) tmpMarkdown.append("%s\n" % aLine)
elif aLine[:4] == "### ": elif aLine[:4] == "### ":
self._theTokens.append(( self._tokens.append((
self.T_HEAD3, nLine, aLine[4:].strip(), None, sAlign self.T_HEAD3, nLine, aLine[4:].strip(), None, sAlign
)) ))
if self._keepMarkdown: if self._keepMarkdown:
tmpMarkdown.append("%s\n" % aLine) tmpMarkdown.append("%s\n" % aLine)
elif aLine[:5] == "#### ": elif aLine[:5] == "#### ":
self._theTokens.append(( self._tokens.append((
self.T_HEAD4, nLine, aLine[5:].strip(), None, sAlign self.T_HEAD4, nLine, aLine[5:].strip(), None, sAlign
)) ))
if self._keepMarkdown: if self._keepMarkdown:
@@ -488,7 +486,7 @@ class Tokenizer(ABC):
else: else:
tStyle = self.T_HEAD1 tStyle = self.T_HEAD1
self._theTokens.append(( self._tokens.append((
tStyle, nLine, aLine[3:].strip(), None, sAlign | self.A_CENTRE tStyle, nLine, aLine[3:].strip(), None, sAlign | self.A_CENTRE
)) ))
if self._keepMarkdown: if self._keepMarkdown:
@@ -501,7 +499,7 @@ class Tokenizer(ABC):
else: else:
tStyle = self.T_HEAD2 tStyle = self.T_HEAD2
self._theTokens.append(( self._tokens.append((
tStyle, nLine, aLine[4:].strip(), None, sAlign tStyle, nLine, aLine[4:].strip(), None, sAlign
)) ))
if self._keepMarkdown: if self._keepMarkdown:
@@ -558,26 +556,26 @@ class Tokenizer(ABC):
# Save the line as is, but append the array of formatting locations # Save the line as is, but append the array of formatting locations
# sorted by position # sorted by position
fmtPos = sorted(fmtPos, key=itemgetter(0)) fmtPos = sorted(fmtPos, key=itemgetter(0))
self._theTokens.append(( self._tokens.append((
self.T_TEXT, nLine, aLine, fmtPos, sAlign self.T_TEXT, nLine, aLine, fmtPos, sAlign
)) ))
if self._keepMarkdown: if self._keepMarkdown:
tmpMarkdown.append("%s\n" % aLine) tmpMarkdown.append("%s\n" % aLine)
# If we have content, turn off the first page flag # If we have content, turn off the first page flag
if self._isFirst and self._theTokens: if self._isFirst and self._tokens:
self._isFirst = False self._isFirst = False
# Make sure the token array doesn't start with a page break # Make sure the token array doesn't start with a page break
# on the very first page, adding a blank first page. # on the very first page, adding a blank first page.
if self._theTokens[0][4] & self.A_PBB: if self._tokens[0][4] & self.A_PBB:
tToken = self._theTokens[0] tToken = self._tokens[0]
self._theTokens[0] = ( self._tokens[0] = (
tToken[0], tToken[1], tToken[2], tToken[3], tToken[4] & ~self.A_PBB tToken[0], tToken[1], tToken[2], tToken[3], tToken[4] & ~self.A_PBB
) )
# Always add an empty line at the end of the file # Always add an empty line at the end of the file
self._theTokens.append(( self._tokens.append((
self.T_EMPTY, nLine, "", None, self.A_NONE self.T_EMPTY, nLine, "", None, self.A_NONE
)) ))
if self._keepMarkdown: if self._keepMarkdown:
@@ -592,13 +590,13 @@ class Tokenizer(ABC):
pToken = (self.T_EMPTY, 0, "", None, self.A_NONE) pToken = (self.T_EMPTY, 0, "", None, self.A_NONE)
nToken = (self.T_EMPTY, 0, "", None, self.A_NONE) nToken = (self.T_EMPTY, 0, "", None, self.A_NONE)
tCount = len(self._theTokens) tCount = len(self._tokens)
for n, tToken in enumerate(self._theTokens): for n, tToken in enumerate(self._tokens):
if n > 0: if n > 0:
pToken = self._theTokens[n-1] pToken = self._tokens[n-1]
if n < tCount - 1: if n < tCount - 1:
nToken = self._theTokens[n+1] nToken = self._tokens[n+1]
if tToken[0] == self.T_KEYWORD: if tToken[0] == self.T_KEYWORD:
aStyle = tToken[4] aStyle = tToken[4]
@@ -606,7 +604,7 @@ class Tokenizer(ABC):
aStyle |= self.A_Z_TOPMRG aStyle |= self.A_Z_TOPMRG
if nToken[0] == self.T_KEYWORD: if nToken[0] == self.T_KEYWORD:
aStyle |= self.A_Z_BTMMRG aStyle |= self.A_Z_BTMMRG
self._theTokens[n] = ( self._tokens[n] = (
tToken[0], tToken[1], tToken[2], tToken[3], aStyle tToken[0], tToken[1], tToken[2], tToken[3], aStyle
) )
@@ -619,7 +617,7 @@ class Tokenizer(ABC):
if not self._isNovel: if not self._isNovel:
return False return False
for n, tToken in enumerate(self._theTokens): for n, tToken in enumerate(self._tokens):
# In case we see text before a scene, we reset the flag # In case we see text before a scene, we reset the flag
if tToken[0] == self.T_TEXT: if tToken[0] == self.T_TEXT:
@@ -629,7 +627,7 @@ class Tokenizer(ABC):
# Partition # Partition
tTemp = self._hFormatter.apply(self._fmtTitle, tToken[2]) tTemp = self._hFormatter.apply(self._fmtTitle, tToken[2])
self._theTokens[n] = ( self._tokens[n] = (
tToken[0], tToken[1], tTemp, None, tToken[4] tToken[0], tToken[1], tTemp, None, tToken[4]
) )
@@ -644,7 +642,7 @@ class Tokenizer(ABC):
tTemp = self._hFormatter.apply(self._fmtChapter, tToken[2]) tTemp = self._hFormatter.apply(self._fmtChapter, tToken[2])
# Format the chapter header # Format the chapter header
self._theTokens[n] = ( self._tokens[n] = (
tToken[0], tToken[1], tTemp, None, tToken[4] tToken[0], tToken[1], tTemp, None, tToken[4]
) )
@@ -659,29 +657,29 @@ class Tokenizer(ABC):
tTemp = self._hFormatter.apply(self._fmtScene, tToken[2]) tTemp = self._hFormatter.apply(self._fmtScene, tToken[2])
if tTemp == "" and self._hideScene: if tTemp == "" and self._hideScene:
self._theTokens[n] = ( self._tokens[n] = (
self.T_EMPTY, tToken[1], "", None, self.A_NONE self.T_EMPTY, tToken[1], "", None, self.A_NONE
) )
elif tTemp == "" and not self._hideScene: elif tTemp == "" and not self._hideScene:
if self._firstScene: if self._firstScene:
self._theTokens[n] = ( self._tokens[n] = (
self.T_EMPTY, tToken[1], "", None, self.A_NONE self.T_EMPTY, tToken[1], "", None, self.A_NONE
) )
else: else:
self._theTokens[n] = ( self._tokens[n] = (
self.T_SKIP, tToken[1], "", None, tToken[4] self.T_SKIP, tToken[1], "", None, tToken[4]
) )
elif tTemp == self._fmtScene: elif tTemp == self._fmtScene:
if self._firstScene: if self._firstScene:
self._theTokens[n] = ( self._tokens[n] = (
self.T_EMPTY, tToken[1], "", None, self.A_NONE self.T_EMPTY, tToken[1], "", None, self.A_NONE
) )
else: else:
self._theTokens[n] = ( self._tokens[n] = (
self.T_SEP, tToken[1], tTemp, None, tToken[4] | self.A_CENTRE self.T_SEP, tToken[1], tTemp, None, tToken[4] | self.A_CENTRE
) )
else: else:
self._theTokens[n] = ( self._tokens[n] = (
tToken[0], tToken[1], tTemp, None, tToken[4] tToken[0], tToken[1], tTemp, None, tToken[4]
) )
@@ -692,19 +690,19 @@ class Tokenizer(ABC):
tTemp = self._hFormatter.apply(self._fmtSection, tToken[2]) tTemp = self._hFormatter.apply(self._fmtSection, tToken[2])
if tTemp == "" and self._hideSection: if tTemp == "" and self._hideSection:
self._theTokens[n] = ( self._tokens[n] = (
self.T_EMPTY, tToken[1], "", None, self.A_NONE self.T_EMPTY, tToken[1], "", None, self.A_NONE
) )
elif tTemp == "" and not self._hideSection: elif tTemp == "" and not self._hideSection:
self._theTokens[n] = ( self._tokens[n] = (
self.T_SKIP, tToken[1], "", None, tToken[4] self.T_SKIP, tToken[1], "", None, tToken[4]
) )
elif tTemp == self._fmtSection: elif tTemp == self._fmtSection:
self._theTokens[n] = ( self._tokens[n] = (
self.T_SEP, tToken[1], tTemp, None, tToken[4] | self.A_CENTRE self.T_SEP, tToken[1], tTemp, None, tToken[4] | self.A_CENTRE
) )
else: else:
self._theTokens[n] = ( self._tokens[n] = (
tToken[0], tToken[1], tTemp, None, tToken[4] tToken[0], tToken[1], tTemp, None, tToken[4]
) )
+5 -5
View File
@@ -98,12 +98,12 @@ class ToMarkdown(Tokenizer):
self.FMT_D_E: "~~", self.FMT_D_E: "~~",
} }
self._theResult = "" self._result = ""
thisPar = [] thisPar = []
tmpResult = [] tmpResult = []
for tType, _, tText, tFormat, tStyle in self._theTokens: for tType, _, tText, tFormat, tStyle in self._tokens:
# Process Text Type # Process Text Type
if tType == self.T_EMPTY: if tType == self.T_EMPTY:
@@ -159,10 +159,10 @@ class ToMarkdown(Tokenizer):
elif tType == self.T_KEYWORD and self._doKeywords: elif tType == self.T_KEYWORD and self._doKeywords:
tmpResult.append(self._formatKeywords(tText, tStyle)) tmpResult.append(self._formatKeywords(tText, tStyle))
self._theResult = "".join(tmpResult) self._result = "".join(tmpResult)
tmpResult = [] tmpResult = []
self._fullMD.append(self._theResult) self._fullMD.append(self._result)
return return
@@ -193,7 +193,7 @@ class ToMarkdown(Tokenizer):
def _formatKeywords(self, tText, tStyle): def _formatKeywords(self, tText, tStyle):
"""Apply Markdown formatting to keywords. """Apply Markdown formatting to keywords.
""" """
isValid, theBits, _ = self.theProject.index.scanThis("@"+tText) isValid, theBits, _ = self._project.index.scanThis("@"+tText)
if not isValid or not theBits: if not isValid or not theBits:
return "" return ""
+10 -10
View File
@@ -263,8 +263,8 @@ class ToOdt(Tokenizer):
# =============== # ===============
if self._headerText == "": if self._headerText == "":
theTitle = self.theProject.data.title or self.theProject.data.name theTitle = self._project.data.title or self._project.data.name
theAuth = self.theProject.data.author theAuth = self._project.data.author
self._headerText = f"{theTitle} / {theAuth} /" self._headerText = f"{theTitle} / {theAuth} /"
# Create Roots # Create Roots
@@ -340,26 +340,26 @@ class ToOdt(Tokenizer):
xMeta.text = f"novelWriter/{__version__}" xMeta.text = f"novelWriter/{__version__}"
xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "initial-creator")) xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "initial-creator"))
xMeta.text = self.theProject.data.author xMeta.text = self._project.data.author
xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "editing-cycles")) xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "editing-cycles"))
xMeta.text = str(self.theProject.data.saveCount) xMeta.text = str(self._project.data.saveCount)
# Format is: PnYnMnDTnHnMnS # Format is: PnYnMnDTnHnMnS
# https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#duration # https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#duration
eT = self.theProject.data.editTime eT = self._project.data.editTime
xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "editing-duration")) xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "editing-duration"))
xMeta.text = f"P{eT//86400:d}DT{eT%86400//3600:d}H{eT%3600//60:d}M{eT%60:d}S" xMeta.text = f"P{eT//86400:d}DT{eT%86400//3600:d}H{eT%3600//60:d}M{eT%60:d}S"
# Dublin Core Meta Data # Dublin Core Meta Data
xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "title")) xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "title"))
xMeta.text = self.theProject.data.title or self.theProject.data.name xMeta.text = self._project.data.title or self._project.data.name
xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "date")) xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "date"))
xMeta.text = timeStamp xMeta.text = timeStamp
xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "creator")) xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "creator"))
xMeta.text = self.theProject.data.author xMeta.text = self._project.data.author
self._pageStyles() self._pageStyles()
self._defaultStyles() self._defaultStyles()
@@ -371,7 +371,7 @@ class ToOdt(Tokenizer):
def doConvert(self): def doConvert(self):
"""Convert the list of text tokens into XML elements. """Convert the list of text tokens into XML elements.
""" """
self._theResult = "" # Not used, but cleared just in case self._result = "" # Not used, but cleared just in case
odtTags = { odtTags = {
self.FMT_B_B: "_B", # Bold open format self.FMT_B_B: "_B", # Bold open format
@@ -385,7 +385,7 @@ class ToOdt(Tokenizer):
thisPar = [] thisPar = []
thisFmt = [] thisFmt = []
parStyle = None parStyle = None
for tType, _, tText, tFormat, tStyle in self._theTokens: for tType, _, tText, tFormat, tStyle in self._tokens:
# Styles # Styles
oStyle = ODTParagraphStyle() oStyle = ODTParagraphStyle()
@@ -567,7 +567,7 @@ class ToOdt(Tokenizer):
def _formatKeywords(self, tText): def _formatKeywords(self, tText):
"""Apply formatting to keywords. """Apply formatting to keywords.
""" """
isValid, theBits, _ = self.theProject.index.scanThis("@"+tText) isValid, theBits, _ = self._project.index.scanThis("@"+tText)
if not isValid or not theBits: if not isValid or not theBits:
return "" return ""
+45 -45
View File
@@ -42,7 +42,7 @@ def testCoreToHtml_ConvertFormat(mockGUI):
theHtml._isFirst = True theHtml._isFirst = True
# Header 1 # Header 1
theHtml._theText = "# Partition\n" theHtml._text = "# Partition\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -50,7 +50,7 @@ def testCoreToHtml_ConvertFormat(mockGUI):
) )
# Header 2 # Header 2
theHtml._theText = "## Chapter Title\n" theHtml._text = "## Chapter Title\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -58,19 +58,19 @@ def testCoreToHtml_ConvertFormat(mockGUI):
) )
# Header 3 # Header 3
theHtml._theText = "### Scene Title\n" theHtml._text = "### Scene Title\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == "<h2>Scene Title</h2>\n" assert theHtml.theResult == "<h2>Scene Title</h2>\n"
# Header 4 # Header 4
theHtml._theText = "#### Section Title\n" theHtml._text = "#### Section Title\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == "<h3>Section Title</h3>\n" assert theHtml.theResult == "<h3>Section Title</h3>\n"
# Title # Title
theHtml._theText = "#! Title\n" theHtml._text = "#! Title\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -78,7 +78,7 @@ def testCoreToHtml_ConvertFormat(mockGUI):
) )
# Unnumbered # Unnumbered
theHtml._theText = "##! Prologue\n" theHtml._text = "##! Prologue\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == "<h1 style='page-break-before: always;'>Prologue</h1>\n" assert theHtml.theResult == "<h1 style='page-break-before: always;'>Prologue</h1>\n"
@@ -92,31 +92,31 @@ def testCoreToHtml_ConvertFormat(mockGUI):
theHtml.setLinkHeaders(True) theHtml.setLinkHeaders(True)
# Header 1 # Header 1
theHtml._theText = "# Heading One\n" theHtml._text = "# Heading One\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == "<h1><a name='T000001'></a>Heading One</h1>\n" assert theHtml.theResult == "<h1><a name='T000001'></a>Heading One</h1>\n"
# Header 2 # Header 2
theHtml._theText = "## Heading Two\n" theHtml._text = "## Heading Two\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == "<h2><a name='T000001'></a>Heading Two</h2>\n" assert theHtml.theResult == "<h2><a name='T000001'></a>Heading Two</h2>\n"
# Header 3 # Header 3
theHtml._theText = "### Heading Three\n" theHtml._text = "### Heading Three\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == "<h3><a name='T000001'></a>Heading Three</h3>\n" assert theHtml.theResult == "<h3><a name='T000001'></a>Heading Three</h3>\n"
# Header 4 # Header 4
theHtml._theText = "#### Heading Four\n" theHtml._text = "#### Heading Four\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == "<h4><a name='T000001'></a>Heading Four</h4>\n" assert theHtml.theResult == "<h4><a name='T000001'></a>Heading Four</h4>\n"
# Title # Title
theHtml._theText = "#! Heading One\n" theHtml._text = "#! Heading One\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -124,7 +124,7 @@ def testCoreToHtml_ConvertFormat(mockGUI):
) )
# Unnumbered # Unnumbered
theHtml._theText = "##! Heading Two\n" theHtml._text = "##! Heading Two\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == "<h2><a name='T000001'></a>Heading Two</h2>\n" assert theHtml.theResult == "<h2><a name='T000001'></a>Heading Two</h2>\n"
@@ -133,7 +133,7 @@ def testCoreToHtml_ConvertFormat(mockGUI):
# ========== # ==========
# Text # Text
theHtml._theText = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n" theHtml._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -142,7 +142,7 @@ def testCoreToHtml_ConvertFormat(mockGUI):
) )
# Text w/Hard Break # Text w/Hard Break
theHtml._theText = "Line one \nLine two \nLine three\n" theHtml._text = "Line one \nLine two \nLine three\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -150,13 +150,13 @@ def testCoreToHtml_ConvertFormat(mockGUI):
) )
# Synopsis # Synopsis
theHtml._theText = "%synopsis: The synopsis ...\n" theHtml._text = "%synopsis: The synopsis ...\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == "" assert theHtml.theResult == ""
theHtml.setSynopsis(True) theHtml.setSynopsis(True)
theHtml._theText = "%synopsis: The synopsis ...\n" theHtml._text = "%synopsis: The synopsis ...\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -164,13 +164,13 @@ def testCoreToHtml_ConvertFormat(mockGUI):
) )
# Comment # Comment
theHtml._theText = "% A comment ...\n" theHtml._text = "% A comment ...\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == "" assert theHtml.theResult == ""
theHtml.setComments(True) theHtml.setComments(True)
theHtml._theText = "% A comment ...\n" theHtml._text = "% A comment ...\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -178,13 +178,13 @@ def testCoreToHtml_ConvertFormat(mockGUI):
) )
# Keywords # Keywords
theHtml._theText = "@char: Bod, Jane\n" theHtml._text = "@char: Bod, Jane\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == "" assert theHtml.theResult == ""
theHtml.setKeywords(True) theHtml.setKeywords(True)
theHtml._theText = "@char: Bod, Jane\n" theHtml._text = "@char: Bod, Jane\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -194,7 +194,7 @@ def testCoreToHtml_ConvertFormat(mockGUI):
# Multiple Keywords # Multiple Keywords
theHtml.setKeywords(True) theHtml.setKeywords(True)
theHtml._theText = "## Chapter\n\n@pov: Bod\n@plot: Main\n@location: Europe\n\n" theHtml._text = "## Chapter\n\n@pov: Bod\n@plot: Main\n@location: Europe\n\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -217,7 +217,7 @@ def testCoreToHtml_ConvertFormat(mockGUI):
theHtml.setPreview(True, True) theHtml.setPreview(True, True)
# Text (HTML4) # Text (HTML4)
theHtml._theText = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n" theHtml._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -244,7 +244,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
# ============== # ==============
# Title # Title
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_TITLE, 1, "A Title", None, theHtml.A_PBB | theHtml.A_CENTRE), (theHtml.T_TITLE, 1, "A Title", None, theHtml.A_PBB | theHtml.A_CENTRE),
(theHtml.T_EMPTY, 1, "", None, theHtml.A_NONE), (theHtml.T_EMPTY, 1, "", None, theHtml.A_NONE),
] ]
@@ -255,7 +255,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
) )
# Unnumbered # Unnumbered
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_UNNUM, 1, "Prologue", None, theHtml.A_PBB), (theHtml.T_UNNUM, 1, "Prologue", None, theHtml.A_PBB),
(theHtml.T_EMPTY, 1, "", None, theHtml.A_NONE), (theHtml.T_EMPTY, 1, "", None, theHtml.A_NONE),
] ]
@@ -269,7 +269,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
# ========== # ==========
# Separator # Separator
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_SEP, 1, "* * *", None, theHtml.A_CENTRE), (theHtml.T_SEP, 1, "* * *", None, theHtml.A_CENTRE),
(theHtml.T_EMPTY, 1, "", None, theHtml.A_NONE), (theHtml.T_EMPTY, 1, "", None, theHtml.A_NONE),
] ]
@@ -277,7 +277,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
assert theHtml.theResult == "<p class='sep' style='text-align: center;'>* * *</p>\n" assert theHtml.theResult == "<p class='sep' style='text-align: center;'>* * *</p>\n"
# Skip # Skip
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_SKIP, 1, "", None, theHtml.A_NONE), (theHtml.T_SKIP, 1, "", None, theHtml.A_NONE),
(theHtml.T_EMPTY, 1, "", None, theHtml.A_NONE), (theHtml.T_EMPTY, 1, "", None, theHtml.A_NONE),
] ]
@@ -291,7 +291,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
# Align Left # Align Left
theHtml.setStyles(False) theHtml.setStyles(False)
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_LEFT), (theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_LEFT),
] ]
theHtml.doConvert() theHtml.doConvert()
@@ -302,7 +302,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
theHtml.setStyles(True) theHtml.setStyles(True)
# Align Left # Align Left
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_LEFT), (theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_LEFT),
] ]
theHtml.doConvert() theHtml.doConvert()
@@ -311,7 +311,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
) )
# Align Right # Align Right
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_RIGHT), (theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_RIGHT),
] ]
theHtml.doConvert() theHtml.doConvert()
@@ -320,7 +320,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
) )
# Align Centre # Align Centre
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_CENTRE), (theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_CENTRE),
] ]
theHtml.doConvert() theHtml.doConvert()
@@ -329,7 +329,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
) )
# Align Justify # Align Justify
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_JUSTIFY), (theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_JUSTIFY),
] ]
theHtml.doConvert() theHtml.doConvert()
@@ -341,7 +341,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
# ========== # ==========
# Page Break Always # Page Break Always
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_PBB | theHtml.A_PBA), (theHtml.T_HEAD1, 1, "A Title", None, theHtml.A_PBB | theHtml.A_PBA),
] ]
theHtml.doConvert() theHtml.doConvert()
@@ -354,7 +354,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
# ====== # ======
# Indent Left # Indent Left
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_TEXT, 1, "Some text ...", [], theHtml.A_IND_L), (theHtml.T_TEXT, 1, "Some text ...", [], theHtml.A_IND_L),
(theHtml.T_EMPTY, 2, "", None, theHtml.A_NONE), (theHtml.T_EMPTY, 2, "", None, theHtml.A_NONE),
] ]
@@ -364,7 +364,7 @@ def testCoreToHtml_ConvertDirect(mockGUI):
) )
# Indent Right # Indent Right
theHtml._theTokens = [ theHtml._tokens = [
(theHtml.T_TEXT, 1, "Some text ...", [], theHtml.A_IND_R), (theHtml.T_TEXT, 1, "Some text ...", [], theHtml.A_IND_R),
(theHtml.T_EMPTY, 2, "", None, theHtml.A_NONE), (theHtml.T_EMPTY, 2, "", None, theHtml.A_NONE),
] ]
@@ -387,28 +387,28 @@ def testCoreToHtml_SpecialCases(mockGUI):
# Greater/Lesser than symbols # Greater/Lesser than symbols
# =========================== # ===========================
theHtml._theText = "Text with > and < with some **bold text** in it.\n" theHtml._text = "Text with > and < with some **bold text** in it.\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
"<p>Text with &gt; and &lt; with some <strong>bold text</strong> in it.</p>\n" "<p>Text with &gt; and &lt; with some <strong>bold text</strong> in it.</p>\n"
) )
theHtml._theText = "Text with some <**bold text**> in it.\n" theHtml._text = "Text with some <**bold text**> in it.\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
"<p>Text with some &lt;<strong>bold text</strong>&gt; in it.</p>\n" "<p>Text with some &lt;<strong>bold text</strong>&gt; in it.</p>\n"
) )
theHtml._theText = "Let's > be > _difficult **shall** > we_?\n" theHtml._text = "Let's > be > _difficult **shall** > we_?\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
"<p>Let's &gt; be &gt; <em>difficult <strong>shall</strong> &gt; we</em>?</p>\n" "<p>Let's &gt; be &gt; <em>difficult <strong>shall</strong> &gt; we</em>?</p>\n"
) )
theHtml._theText = "Test > text _<**bold**>_ and more.\n" theHtml._text = "Test > text _<**bold**>_ and more.\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -420,7 +420,7 @@ def testCoreToHtml_SpecialCases(mockGUI):
# See: https://github.com/vkbo/novelWriter/issues/950 # See: https://github.com/vkbo/novelWriter/issues/950
theHtml.setComments(True) theHtml.setComments(True)
theHtml._theText = "% Test > text _<**bold**>_ and more.\n" theHtml._text = "% Test > text _<**bold**>_ and more.\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -429,7 +429,7 @@ def testCoreToHtml_SpecialCases(mockGUI):
"</p>\n" "</p>\n"
) )
theHtml._theText = "## Heading <1>\n" theHtml._text = "## Heading <1>\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -440,7 +440,7 @@ def testCoreToHtml_SpecialCases(mockGUI):
# ==================== # ====================
# See: https://github.com/vkbo/novelWriter/issues/1412 # See: https://github.com/vkbo/novelWriter/issues/1412
theHtml._theText = "Test text \\**_bold_** and more.\n" theHtml._text = "Test text \\**_bold_** and more.\n"
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
assert theHtml.theResult == ( assert theHtml.theResult == (
@@ -502,7 +502,7 @@ def testCoreToHtml_Complex(mockGUI, fncPath):
] ]
for i in range(len(docText)): for i in range(len(docText)):
theHtml._theText = docText[i] theHtml._text = docText[i]
theHtml.doPreProcessing() theHtml.doPreProcessing()
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
@@ -556,7 +556,7 @@ def testCoreToHtml_Methods(mockGUI):
# Auto-Replace, keep Unicode # Auto-Replace, keep Unicode
docText = "Text with <brackets> & shortdash, long—dash …\n" docText = "Text with <brackets> & shortdash, long—dash …\n"
theHtml._theText = docText theHtml._text = docText
theHtml.setReplaceUnicode(False) theHtml.setReplaceUnicode(False)
theHtml.doPreProcessing() theHtml.doPreProcessing()
theHtml.tokenizeText() theHtml.tokenizeText()
@@ -567,7 +567,7 @@ def testCoreToHtml_Methods(mockGUI):
# Auto-Replace, replace Unicode # Auto-Replace, replace Unicode
docText = "Text with <brackets> & shortdash, long—dash …\n" docText = "Text with <brackets> & shortdash, long—dash …\n"
theHtml._theText = docText theHtml._text = docText
theHtml.setReplaceUnicode(True) theHtml.setReplaceUnicode(True)
theHtml.doPreProcessing() theHtml.doPreProcessing()
theHtml.tokenizeText() theHtml.tokenizeText()
@@ -578,7 +578,7 @@ def testCoreToHtml_Methods(mockGUI):
# With Preview # With Preview
theHtml.setPreview(True, True) theHtml.setPreview(True, True)
theHtml._theText = docText theHtml._text = docText
theHtml.doPreProcessing() theHtml.doPreProcessing()
theHtml.tokenizeText() theHtml.tokenizeText()
theHtml.doConvert() theHtml.doConvert()
+121 -121
View File
@@ -169,32 +169,32 @@ def testCoreToken_TextOps(monkeypatch, mockGUI, mockRnd, fncPath):
# First Page # First Page
assert theToken.addRootHeading(C.hPlotRoot) is True assert theToken.addRootHeading(C.hPlotRoot) is True
assert theToken.theMarkdown[-1] == "# Notes: Plot\n\n" assert theToken.theMarkdown[-1] == "# Notes: Plot\n\n"
assert theToken._theTokens[-1] == ( assert theToken._tokens[-1] == (
Tokenizer.T_TITLE, 0, "Notes: Plot", None, Tokenizer.A_CENTRE Tokenizer.T_TITLE, 0, "Notes: Plot", None, Tokenizer.A_CENTRE
) )
# Not First Page # Not First Page
assert theToken.addRootHeading(C.hPlotRoot) is True assert theToken.addRootHeading(C.hPlotRoot) is True
assert theToken.theMarkdown[-1] == "# Notes: Plot\n\n" assert theToken.theMarkdown[-1] == "# Notes: Plot\n\n"
assert theToken._theTokens[-1] == ( assert theToken._tokens[-1] == (
Tokenizer.T_TITLE, 0, "Notes: Plot", None, Tokenizer.A_CENTRE | Tokenizer.A_PBB Tokenizer.T_TITLE, 0, "Notes: Plot", None, Tokenizer.A_CENTRE | Tokenizer.A_PBB
) )
# Set Text # Set Text
assert theToken.setText("stuff") is False assert theToken.setText("stuff") is False
assert theToken.setText(C.hSceneDoc) is True assert theToken.setText(C.hSceneDoc) is True
assert theToken._theText == docText assert theToken._text == docText
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr("novelwriter.constants.nwConst.MAX_DOCSIZE", 100) mp.setattr("novelwriter.constants.nwConst.MAX_DOCSIZE", 100)
assert theToken.setText(C.hSceneDoc, docText) is True assert theToken.setText(C.hSceneDoc, docText) is True
assert theToken._theText == ( assert theToken._text == (
"# ERROR\n\n" "# ERROR\n\n"
"Document 'New Scene' is too big (0.00 MB). Skipping.\n\n" "Document 'New Scene' is too big (0.00 MB). Skipping.\n\n"
) )
assert theToken.setText(C.hSceneDoc, docText) is True assert theToken.setText(C.hSceneDoc, docText) is True
assert theToken._theText == docText assert theToken._text == docText
assert theToken._isNone is False assert theToken._isNone is False
assert theToken._isNovel is True assert theToken._isNovel is True
@@ -202,7 +202,7 @@ def testCoreToken_TextOps(monkeypatch, mockGUI, mockRnd, fncPath):
# Pre Processing # Pre Processing
theToken.doPreProcessing() theToken.doPreProcessing()
assert theToken._theText == docTextR assert theToken._text == docTextR
# Save File # Save File
savePath = fncPath / "dump.nwd" savePath = fncPath / "dump.nwd"
@@ -246,10 +246,10 @@ def testCoreToken_HeaderFormat(mockGUI):
theToken._isNovel = True theToken._isNovel = True
theToken._isNote = False theToken._isNote = False
theToken._isFirst = True theToken._isFirst = True
theToken._theText = "#! Novel Title\n" theToken._text = "#! Novel Title\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_TITLE, 1, "Novel Title", None, Tokenizer.A_CENTRE), (Tokenizer.T_TITLE, 1, "Novel Title", None, Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -259,10 +259,10 @@ def testCoreToken_HeaderFormat(mockGUI):
theToken._isNovel = False theToken._isNovel = False
theToken._isNote = True theToken._isNote = True
theToken._isFirst = True theToken._isFirst = True
theToken._theText = "#! Note Title\n" theToken._text = "#! Note Title\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Note Title", None, Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "Note Title", None, Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -275,10 +275,10 @@ def testCoreToken_HeaderFormat(mockGUI):
theToken._isNovel = True theToken._isNovel = True
theToken._isNote = False theToken._isNote = False
theToken._isFirst = True theToken._isFirst = True
theToken._theText = "# Novel Title\n" theToken._text = "# Novel Title\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Novel Title", None, Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "Novel Title", None, Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -288,10 +288,10 @@ def testCoreToken_HeaderFormat(mockGUI):
theToken._isNovel = False theToken._isNovel = False
theToken._isNote = True theToken._isNote = True
theToken._isFirst = True theToken._isFirst = True
theToken._theText = "# Note Title\n" theToken._text = "# Note Title\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Note Title", None, Tokenizer.A_NONE), (Tokenizer.T_HEAD1, 1, "Note Title", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -303,10 +303,10 @@ def testCoreToken_HeaderFormat(mockGUI):
# Story File # Story File
theToken._isNovel = True theToken._isNovel = True
theToken._isNote = False theToken._isNote = False
theToken._theText = "## Chapter One\n" theToken._text = "## Chapter One\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD2, 1, "Chapter One", None, Tokenizer.A_PBB), (Tokenizer.T_HEAD2, 1, "Chapter One", None, Tokenizer.A_PBB),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -315,10 +315,10 @@ def testCoreToken_HeaderFormat(mockGUI):
# Note File # Note File
theToken._isNovel = False theToken._isNovel = False
theToken._isNote = True theToken._isNote = True
theToken._theText = "## Heading 2\n" theToken._text = "## Heading 2\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD2, 1, "Heading 2", None, Tokenizer.A_NONE), (Tokenizer.T_HEAD2, 1, "Heading 2", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -330,10 +330,10 @@ def testCoreToken_HeaderFormat(mockGUI):
# Story File # Story File
theToken._isNovel = True theToken._isNovel = True
theToken._isNote = False theToken._isNote = False
theToken._theText = "### Scene One\n" theToken._text = "### Scene One\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD3, 1, "Scene One", None, Tokenizer.A_NONE), (Tokenizer.T_HEAD3, 1, "Scene One", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -342,10 +342,10 @@ def testCoreToken_HeaderFormat(mockGUI):
# Note File # Note File
theToken._isNovel = False theToken._isNovel = False
theToken._isNote = True theToken._isNote = True
theToken._theText = "### Heading 3\n" theToken._text = "### Heading 3\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD3, 1, "Heading 3", None, Tokenizer.A_NONE), (Tokenizer.T_HEAD3, 1, "Heading 3", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -357,10 +357,10 @@ def testCoreToken_HeaderFormat(mockGUI):
# Story File # Story File
theToken._isNovel = True theToken._isNovel = True
theToken._isNote = False theToken._isNote = False
theToken._theText = "#### A Section\n" theToken._text = "#### A Section\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD4, 1, "A Section", None, Tokenizer.A_NONE), (Tokenizer.T_HEAD4, 1, "A Section", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -369,10 +369,10 @@ def testCoreToken_HeaderFormat(mockGUI):
# Note File # Note File
theToken._isNovel = False theToken._isNovel = False
theToken._isNote = True theToken._isNote = True
theToken._theText = "#### Heading 4\n" theToken._text = "#### Heading 4\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD4, 1, "Heading 4", None, Tokenizer.A_NONE), (Tokenizer.T_HEAD4, 1, "Heading 4", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -384,10 +384,10 @@ def testCoreToken_HeaderFormat(mockGUI):
# Story File # Story File
theToken._isNovel = True theToken._isNovel = True
theToken._isNote = False theToken._isNote = False
theToken._theText = "#! Title\n" theToken._text = "#! Title\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_TITLE, 1, "Title", None, Tokenizer.A_CENTRE), (Tokenizer.T_TITLE, 1, "Title", None, Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -396,10 +396,10 @@ def testCoreToken_HeaderFormat(mockGUI):
# Note File # Note File
theToken._isNovel = False theToken._isNovel = False
theToken._isNote = True theToken._isNote = True
theToken._theText = "#! Title\n" theToken._text = "#! Title\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Title", None, Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "Title", None, Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -411,10 +411,10 @@ def testCoreToken_HeaderFormat(mockGUI):
# Story File # Story File
theToken._isNovel = True theToken._isNovel = True
theToken._isNote = False theToken._isNote = False
theToken._theText = "##! Prologue\n" theToken._text = "##! Prologue\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_UNNUM, 1, "Prologue", None, Tokenizer.A_PBB), (Tokenizer.T_UNNUM, 1, "Prologue", None, Tokenizer.A_PBB),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -423,10 +423,10 @@ def testCoreToken_HeaderFormat(mockGUI):
# Note File # Note File
theToken._isNovel = False theToken._isNovel = False
theToken._isNote = True theToken._isNote = True
theToken._theText = "##! Prologue\n" theToken._text = "##! Prologue\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD2, 1, "Prologue", None, Tokenizer.A_NONE), (Tokenizer.T_HEAD2, 1, "Prologue", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -444,9 +444,9 @@ def testCoreToken_MetaFormat(mockGUI):
theToken.setKeepMarkdown(True) theToken.setKeepMarkdown(True)
# Comment # Comment
theToken._theText = "% A comment\n" theToken._text = "% A comment\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_COMMENT, 1, "A comment", None, Tokenizer.A_NONE), (Tokenizer.T_COMMENT, 1, "A comment", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -457,15 +457,15 @@ def testCoreToken_MetaFormat(mockGUI):
assert theToken.theMarkdown[-1] == "% A comment\n\n" assert theToken.theMarkdown[-1] == "% A comment\n\n"
# Symopsis # Symopsis
theToken._theText = "%synopsis: The synopsis\n" theToken._text = "%synopsis: The synopsis\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_SYNOPSIS, 1, "The synopsis", None, Tokenizer.A_NONE), (Tokenizer.T_SYNOPSIS, 1, "The synopsis", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
theToken._theText = "% synopsis: The synopsis\n" theToken._text = "% synopsis: The synopsis\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_SYNOPSIS, 1, "The synopsis", None, Tokenizer.A_NONE), (Tokenizer.T_SYNOPSIS, 1, "The synopsis", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -476,9 +476,9 @@ def testCoreToken_MetaFormat(mockGUI):
assert theToken.theMarkdown[-1] == "% synopsis: The synopsis\n\n" assert theToken.theMarkdown[-1] == "% synopsis: The synopsis\n\n"
# Keyword # Keyword
theToken._theText = "@char: Bod\n" theToken._text = "@char: Bod\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_KEYWORD, 1, "char: Bod", None, Tokenizer.A_NONE), (Tokenizer.T_KEYWORD, 1, "char: Bod", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -488,12 +488,12 @@ def testCoreToken_MetaFormat(mockGUI):
theToken.tokenizeText() theToken.tokenizeText()
assert theToken.theMarkdown[-1] == "@char: Bod\n\n" assert theToken.theMarkdown[-1] == "@char: Bod\n\n"
theToken._theText = "@pov: Bod\n@plot: Main\n@location: Europe\n" theToken._text = "@pov: Bod\n@plot: Main\n@location: Europe\n"
theToken.tokenizeText() theToken.tokenizeText()
styTop = Tokenizer.A_NONE | Tokenizer.A_Z_BTMMRG styTop = Tokenizer.A_NONE | Tokenizer.A_Z_BTMMRG
styMid = Tokenizer.A_NONE | Tokenizer.A_Z_BTMMRG | Tokenizer.A_Z_TOPMRG styMid = Tokenizer.A_NONE | Tokenizer.A_Z_BTMMRG | Tokenizer.A_Z_TOPMRG
styBtm = Tokenizer.A_NONE | Tokenizer.A_Z_TOPMRG styBtm = Tokenizer.A_NONE | Tokenizer.A_Z_TOPMRG
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_KEYWORD, 1, "pov: Bod", None, styTop), (Tokenizer.T_KEYWORD, 1, "pov: Bod", None, styTop),
(Tokenizer.T_KEYWORD, 2, "plot: Main", None, styMid), (Tokenizer.T_KEYWORD, 2, "plot: Main", None, styMid),
(Tokenizer.T_KEYWORD, 3, "location: Europe", None, styBtm), (Tokenizer.T_KEYWORD, 3, "location: Europe", None, styBtm),
@@ -515,7 +515,7 @@ def testCoreToken_MarginFormat(mockGUI):
# Alignment and Indentation # Alignment and Indentation
dblIndent = Tokenizer.A_IND_L | Tokenizer.A_IND_R dblIndent = Tokenizer.A_IND_L | Tokenizer.A_IND_R
rIndAlign = Tokenizer.A_RIGHT | Tokenizer.A_IND_R rIndAlign = Tokenizer.A_RIGHT | Tokenizer.A_IND_R
theToken._theText = ( theToken._text = (
"Some regular text\n\n" "Some regular text\n\n"
"Some left-aligned text <<\n\n" "Some left-aligned text <<\n\n"
">> Some right-aligned text\n\n" ">> Some right-aligned text\n\n"
@@ -526,7 +526,7 @@ def testCoreToken_MarginFormat(mockGUI):
">> Right-indent, right-aligned <\n\n" ">> Right-indent, right-aligned <\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_TEXT, 1, "Some regular text", [], Tokenizer.A_NONE), (Tokenizer.T_TEXT, 1, "Some regular text", [], Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE),
(Tokenizer.T_TEXT, 3, "Some left-aligned text", [], Tokenizer.A_LEFT), (Tokenizer.T_TEXT, 3, "Some left-aligned text", [], Tokenizer.A_LEFT),
@@ -568,9 +568,9 @@ def testCoreToken_TextFormat(mockGUI):
theToken.setKeepMarkdown(True) theToken.setKeepMarkdown(True)
# Text # Text
theToken._theText = "Some plain text\non two lines\n\n\n" theToken._text = "Some plain text\non two lines\n\n\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_TEXT, 1, "Some plain text", [], Tokenizer.A_NONE), (Tokenizer.T_TEXT, 1, "Some plain text", [], Tokenizer.A_NONE),
(Tokenizer.T_TEXT, 2, "on two lines", [], Tokenizer.A_NONE), (Tokenizer.T_TEXT, 2, "on two lines", [], Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 3, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 3, "", None, Tokenizer.A_NONE),
@@ -581,7 +581,7 @@ def testCoreToken_TextFormat(mockGUI):
theToken.setBodyText(False) theToken.setBodyText(False)
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_EMPTY, 3, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 3, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE),
@@ -590,9 +590,9 @@ def testCoreToken_TextFormat(mockGUI):
theToken.setBodyText(True) theToken.setBodyText(True)
# Text Emphasis # Text Emphasis
theToken._theText = "Some **bolded text** on this lines\n" theToken._text = "Some **bolded text** on this lines\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
( (
Tokenizer.T_TEXT, 1, Tokenizer.T_TEXT, 1,
"Some **bolded text** on this lines", "Some **bolded text** on this lines",
@@ -606,9 +606,9 @@ def testCoreToken_TextFormat(mockGUI):
] ]
assert theToken.theMarkdown[-1] == "Some **bolded text** on this lines\n\n" assert theToken.theMarkdown[-1] == "Some **bolded text** on this lines\n\n"
theToken._theText = "Some _italic text_ on this lines\n" theToken._text = "Some _italic text_ on this lines\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
( (
Tokenizer.T_TEXT, 1, Tokenizer.T_TEXT, 1,
"Some _italic text_ on this lines", "Some _italic text_ on this lines",
@@ -622,9 +622,9 @@ def testCoreToken_TextFormat(mockGUI):
] ]
assert theToken.theMarkdown[-1] == "Some _italic text_ on this lines\n\n" assert theToken.theMarkdown[-1] == "Some _italic text_ on this lines\n\n"
theToken._theText = "Some **_bold italic text_** on this lines\n" theToken._text = "Some **_bold italic text_** on this lines\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
( (
Tokenizer.T_TEXT, 1, Tokenizer.T_TEXT, 1,
"Some **_bold italic text_** on this lines", "Some **_bold italic text_** on this lines",
@@ -640,9 +640,9 @@ def testCoreToken_TextFormat(mockGUI):
] ]
assert theToken.theMarkdown[-1] == "Some **_bold italic text_** on this lines\n\n" assert theToken.theMarkdown[-1] == "Some **_bold italic text_** on this lines\n\n"
theToken._theText = "Some ~~strikethrough text~~ on this lines\n" theToken._text = "Some ~~strikethrough text~~ on this lines\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
( (
Tokenizer.T_TEXT, 1, Tokenizer.T_TEXT, 1,
"Some ~~strikethrough text~~ on this lines", "Some ~~strikethrough text~~ on this lines",
@@ -656,9 +656,9 @@ def testCoreToken_TextFormat(mockGUI):
] ]
assert theToken.theMarkdown[-1] == "Some ~~strikethrough text~~ on this lines\n\n" assert theToken.theMarkdown[-1] == "Some ~~strikethrough text~~ on this lines\n\n"
theToken._theText = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n" theToken._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
( (
Tokenizer.T_TEXT, 1, Tokenizer.T_TEXT, 1,
"Some **nested bold and _italic_ and ~~strikethrough~~ text** here", "Some **nested bold and _italic_ and ~~strikethrough~~ text** here",
@@ -704,44 +704,44 @@ def testCoreToken_SpecialFormat(mockGUI):
# Command wo/Space # Command wo/Space
theToken._isFirst = True theToken._isFirst = True
theToken._theText = ( theToken._text = (
"# Title One\n\n" "# Title One\n\n"
"[NEWPAGE]\n\n" "[NEWPAGE]\n\n"
"# Title Two\n\n" "# Title Two\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == correctResp assert theToken._tokens == correctResp
# Command w/Space # Command w/Space
theToken._isFirst = True theToken._isFirst = True
theToken._theText = ( theToken._text = (
"# Title One\n\n" "# Title One\n\n"
"[NEW PAGE]\n\n" "[NEW PAGE]\n\n"
"# Title Two\n\n" "# Title Two\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == correctResp assert theToken._tokens == correctResp
# Trailing Spaces # Trailing Spaces
theToken._isFirst = True theToken._isFirst = True
theToken._theText = ( theToken._text = (
"# Title One\n\n" "# Title One\n\n"
"[NEW PAGE] \t\n\n" "[NEW PAGE] \t\n\n"
"# Title Two\n\n" "# Title Two\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == correctResp assert theToken._tokens == correctResp
# Single Empty Paragraph # Single Empty Paragraph
# ====================== # ======================
theToken._theText = ( theToken._text = (
"# Title One\n\n" "# Title One\n\n"
"[VSPACE] \n\n" "[VSPACE] \n\n"
"Some text to go here ...\n\n" "Some text to go here ...\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE),
(Tokenizer.T_SKIP, 3, "", None, Tokenizer.A_NONE), (Tokenizer.T_SKIP, 3, "", None, Tokenizer.A_NONE),
@@ -755,13 +755,13 @@ def testCoreToken_SpecialFormat(mockGUI):
# ========================= # =========================
# One Skip # One Skip
theToken._theText = ( theToken._text = (
"# Title One\n\n" "# Title One\n\n"
"[VSPACE:1] \n\n" "[VSPACE:1] \n\n"
"Some text to go here ...\n\n" "Some text to go here ...\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE),
(Tokenizer.T_SKIP, 3, "", None, Tokenizer.A_NONE), (Tokenizer.T_SKIP, 3, "", None, Tokenizer.A_NONE),
@@ -772,13 +772,13 @@ def testCoreToken_SpecialFormat(mockGUI):
] ]
# Three Skips # Three Skips
theToken._theText = ( theToken._text = (
"# Title One\n\n" "# Title One\n\n"
"[VSPACE:3] \n\n" "[VSPACE:3] \n\n"
"Some text to go here ...\n\n" "Some text to go here ...\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE),
(Tokenizer.T_SKIP, 3, "", None, Tokenizer.A_NONE), (Tokenizer.T_SKIP, 3, "", None, Tokenizer.A_NONE),
@@ -791,13 +791,13 @@ def testCoreToken_SpecialFormat(mockGUI):
] ]
# Malformed Command, Case 1 # Malformed Command, Case 1
theToken._theText = ( theToken._text = (
"# Title One\n\n" "# Title One\n\n"
"[VSPACE:3xa] \n\n" "[VSPACE:3xa] \n\n"
"Some text to go here ...\n\n" "Some text to go here ...\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE),
@@ -807,13 +807,13 @@ def testCoreToken_SpecialFormat(mockGUI):
] ]
# Malformed Command, Case 2 # Malformed Command, Case 2
theToken._theText = ( theToken._text = (
"# Title One\n\n" "# Title One\n\n"
"[VSPACE:3.5]\n\n" "[VSPACE:3.5]\n\n"
"Some text to go here ...\n\n" "Some text to go here ...\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE),
@@ -823,13 +823,13 @@ def testCoreToken_SpecialFormat(mockGUI):
] ]
# Malformed Command, Case 3 # Malformed Command, Case 3
theToken._theText = ( theToken._text = (
"# Title One\n\n" "# Title One\n\n"
"[VSPACE:-1]\n\n" "[VSPACE:-1]\n\n"
"Some text to go here ...\n\n" "Some text to go here ...\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE),
@@ -842,14 +842,14 @@ def testCoreToken_SpecialFormat(mockGUI):
# ============================== # ==============================
# Single Skip # Single Skip
theToken._theText = ( theToken._text = (
"# Title One\n\n" "# Title One\n\n"
"[NEW PAGE]\n\n" "[NEW PAGE]\n\n"
"[VSPACE]\n\n" "[VSPACE]\n\n"
"Some text to go here ...\n\n" "Some text to go here ...\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE),
@@ -861,14 +861,14 @@ def testCoreToken_SpecialFormat(mockGUI):
] ]
# Multiple Skip # Multiple Skip
theToken._theText = ( theToken._text = (
"# Title One\n\n" "# Title One\n\n"
"[NEW PAGE]\n\n" "[NEW PAGE]\n\n"
"[VSPACE:3]\n\n" "[VSPACE:3]\n\n"
"Some text to go here ...\n\n" "Some text to go here ...\n\n"
) )
theToken.tokenizeText() theToken.tokenizeText()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "Title One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 2, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 4, "", None, Tokenizer.A_NONE),
@@ -894,7 +894,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
theToken = BareTokenizer(theProject) theToken = BareTokenizer(theProject)
# Nothing # Nothing
theToken._theText = "Some text ...\n" theToken._text = "Some text ...\n"
assert theToken.doHeaders() is False assert theToken.doHeaders() is False
theToken._isNone = True theToken._isNone = True
assert theToken.doHeaders() is False assert theToken.doHeaders() is False
@@ -917,22 +917,22 @@ def testCoreToken_ProcessHeaders(mockGUI):
# H1: Title, First Page # H1: Title, First Page
assert theToken._isFirst is True assert theToken._isFirst is True
theToken._theText = "# Part One\n" theToken._text = "# Part One\n"
theToken.setTitleFormat(f"T: {nwHeadFmt.TITLE}") theToken.setTitleFormat(f"T: {nwHeadFmt.TITLE}")
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "T: Part One", None, Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "T: Part One", None, Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H1: Title, Not First Page # H1: Title, Not First Page
assert theToken._isFirst is False assert theToken._isFirst is False
theToken._theText = "# Part One\n" theToken._text = "# Part One\n"
theToken.setTitleFormat(f"T: {nwHeadFmt.TITLE}") theToken.setTitleFormat(f"T: {nwHeadFmt.TITLE}")
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD1, 1, "T: Part One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE), (Tokenizer.T_HEAD1, 1, "T: Part One", None, Tokenizer.A_PBB | Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -941,52 +941,52 @@ def testCoreToken_ProcessHeaders(mockGUI):
# ======== # ========
# H2: Chapter # H2: Chapter
theToken._theText = "## Chapter One\n" theToken._text = "## Chapter One\n"
theToken.setChapterFormat(f"C: {nwHeadFmt.TITLE}") theToken.setChapterFormat(f"C: {nwHeadFmt.TITLE}")
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD2, 1, "C: Chapter One", None, Tokenizer.A_PBB), (Tokenizer.T_HEAD2, 1, "C: Chapter One", None, Tokenizer.A_PBB),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H2: Unnumbered Chapter # H2: Unnumbered Chapter
theToken._theText = "##! Prologue\n" theToken._text = "##! Prologue\n"
theToken.setUnNumberedFormat(f"U: {nwHeadFmt.TITLE}") theToken.setUnNumberedFormat(f"U: {nwHeadFmt.TITLE}")
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_UNNUM, 1, "U: Prologue", None, Tokenizer.A_PBB), (Tokenizer.T_UNNUM, 1, "U: Prologue", None, Tokenizer.A_PBB),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H2: Chapter Word Number # H2: Chapter Word Number
theToken._theText = "## Chapter\n" theToken._text = "## Chapter\n"
theToken.setChapterFormat(f"Chapter {nwHeadFmt.CH_WORD}") theToken.setChapterFormat(f"Chapter {nwHeadFmt.CH_WORD}")
theToken._hFormatter._chCount = 0 theToken._hFormatter._chCount = 0
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD2, 1, "Chapter One", None, Tokenizer.A_PBB), (Tokenizer.T_HEAD2, 1, "Chapter One", None, Tokenizer.A_PBB),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H2: Chapter Roman Number Upper Case # H2: Chapter Roman Number Upper Case
theToken._theText = "## Chapter\n" theToken._text = "## Chapter\n"
theToken.setChapterFormat(f"Chapter {nwHeadFmt.CH_ROMU}") theToken.setChapterFormat(f"Chapter {nwHeadFmt.CH_ROMU}")
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD2, 1, "Chapter II", None, Tokenizer.A_PBB), (Tokenizer.T_HEAD2, 1, "Chapter II", None, Tokenizer.A_PBB),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H2: Chapter Roman Number Lower Case # H2: Chapter Roman Number Lower Case
theToken._theText = "## Chapter\n" theToken._text = "## Chapter\n"
theToken.setChapterFormat(f"Chapter {nwHeadFmt.CH_ROML}") theToken.setChapterFormat(f"Chapter {nwHeadFmt.CH_ROML}")
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD2, 1, "Chapter iii", None, Tokenizer.A_PBB), (Tokenizer.T_HEAD2, 1, "Chapter iii", None, Tokenizer.A_PBB),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -995,89 +995,89 @@ def testCoreToken_ProcessHeaders(mockGUI):
# ====== # ======
# H3: Scene w/Title # H3: Scene w/Title
theToken._theText = "### Scene One\n" theToken._text = "### Scene One\n"
theToken.setSceneFormat(f"S: {nwHeadFmt.TITLE}", False) theToken.setSceneFormat(f"S: {nwHeadFmt.TITLE}", False)
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD3, 1, "S: Scene One", None, Tokenizer.A_NONE), (Tokenizer.T_HEAD3, 1, "S: Scene One", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H3: Scene Hidden wo/Format # H3: Scene Hidden wo/Format
theToken._theText = "### Scene One\n" theToken._text = "### Scene One\n"
theToken.setSceneFormat("", True) theToken.setSceneFormat("", True)
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H3: Scene wo/Format, first # H3: Scene wo/Format, first
theToken._theText = "### Scene One\n" theToken._text = "### Scene One\n"
theToken.setSceneFormat("", False) theToken.setSceneFormat("", False)
theToken._firstScene = True theToken._firstScene = True
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H3: Scene wo/Format, not first # H3: Scene wo/Format, not first
theToken._theText = "### Scene One\n" theToken._text = "### Scene One\n"
theToken.setSceneFormat("", False) theToken.setSceneFormat("", False)
theToken._firstScene = False theToken._firstScene = False
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_SKIP, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_SKIP, 1, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H3: Scene Separator, first # H3: Scene Separator, first
theToken._theText = "### Scene One\n" theToken._text = "### Scene One\n"
theToken.setSceneFormat("* * *", False) theToken.setSceneFormat("* * *", False)
theToken._firstScene = True theToken._firstScene = True
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H3: Scene Separator, not first # H3: Scene Separator, not first
theToken._theText = "### Scene One\n" theToken._text = "### Scene One\n"
theToken.setSceneFormat("* * *", False) theToken.setSceneFormat("* * *", False)
theToken._firstScene = False theToken._firstScene = False
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_SEP, 1, "* * *", None, Tokenizer.A_CENTRE), (Tokenizer.T_SEP, 1, "* * *", None, Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H3: Scene w/Absolute Number # H3: Scene w/Absolute Number
theToken._theText = "### A Scene\n" theToken._text = "### A Scene\n"
theToken.setSceneFormat(f"Scene {nwHeadFmt.SC_ABS}", False) theToken.setSceneFormat(f"Scene {nwHeadFmt.SC_ABS}", False)
theToken._hFormatter._scAbsCount = 0 theToken._hFormatter._scAbsCount = 0
theToken._hFormatter._scChCount = 0 theToken._hFormatter._scChCount = 0
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD3, 1, "Scene 1", None, Tokenizer.A_NONE), (Tokenizer.T_HEAD3, 1, "Scene 1", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H3: Scene w/Chapter Number # H3: Scene w/Chapter Number
theToken._theText = "### A Scene\n" theToken._text = "### A Scene\n"
theToken.setSceneFormat(f"Scene {nwHeadFmt.CH_NUM}.{nwHeadFmt.SC_NUM}", False) theToken.setSceneFormat(f"Scene {nwHeadFmt.CH_NUM}.{nwHeadFmt.SC_NUM}", False)
theToken._hFormatter._scAbsCount = 0 theToken._hFormatter._scAbsCount = 0
theToken._hFormatter._scChCount = 1 theToken._hFormatter._scChCount = 1
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD3, 1, "Scene 3.2", None, Tokenizer.A_NONE), (Tokenizer.T_HEAD3, 1, "Scene 3.2", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -1086,41 +1086,41 @@ def testCoreToken_ProcessHeaders(mockGUI):
# ======== # ========
# H4: Section Hidden wo/Format # H4: Section Hidden wo/Format
theToken._theText = "#### A Section\n" theToken._text = "#### A Section\n"
theToken.setSectionFormat(r"", True) theToken.setSectionFormat(r"", True)
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H4: Section Visible wo/Format # H4: Section Visible wo/Format
theToken._theText = "#### A Section\n" theToken._text = "#### A Section\n"
theToken.setSectionFormat("", False) theToken.setSectionFormat("", False)
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_SKIP, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_SKIP, 1, "", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H4: Section w/Format # H4: Section w/Format
theToken._theText = "#### A Section\n" theToken._text = "#### A Section\n"
theToken.setSectionFormat(f"X: {nwHeadFmt.TITLE}", False) theToken.setSectionFormat(f"X: {nwHeadFmt.TITLE}", False)
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_HEAD4, 1, "X: A Section", None, Tokenizer.A_NONE), (Tokenizer.T_HEAD4, 1, "X: A Section", None, Tokenizer.A_NONE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
# H4: Section Separator # H4: Section Separator
theToken._theText = "#### A Section\n" theToken._text = "#### A Section\n"
theToken.setSectionFormat("* * *", False) theToken.setSectionFormat("* * *", False)
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._theTokens == [ assert theToken._tokens == [
(Tokenizer.T_SEP, 1, "* * *", None, Tokenizer.A_CENTRE), (Tokenizer.T_SEP, 1, "* * *", None, Tokenizer.A_CENTRE),
(Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE), (Tokenizer.T_EMPTY, 1, "", None, Tokenizer.A_NONE),
] ]
@@ -1128,7 +1128,7 @@ def testCoreToken_ProcessHeaders(mockGUI):
# Check the first scene detector # Check the first scene detector
assert theToken._firstScene is False assert theToken._firstScene is False
theToken._firstScene = True theToken._firstScene = True
theToken._theText = "Some text ...\n" theToken._text = "Some text ...\n"
theToken.tokenizeText() theToken.tokenizeText()
theToken.doHeaders() theToken.doHeaders()
assert theToken._firstScene is False assert theToken._firstScene is False
+21 -21
View File
@@ -42,37 +42,37 @@ def testCoreToMarkdown_ConvertFormat(mockGUI):
theMD._isFirst = True theMD._isFirst = True
# Header 1 # Header 1
theMD._theText = "# Partition\n" theMD._text = "# Partition\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "# Partition\n\n" assert theMD.theResult == "# Partition\n\n"
# Header 2 # Header 2
theMD._theText = "## Chapter Title\n" theMD._text = "## Chapter Title\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "## Chapter Title\n\n" assert theMD.theResult == "## Chapter Title\n\n"
# Header 3 # Header 3
theMD._theText = "### Scene Title\n" theMD._text = "### Scene Title\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "### Scene Title\n\n" assert theMD.theResult == "### Scene Title\n\n"
# Header 4 # Header 4
theMD._theText = "#### Section Title\n" theMD._text = "#### Section Title\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "#### Section Title\n\n" assert theMD.theResult == "#### Section Title\n\n"
# Title # Title
theMD._theText = "#! Title\n" theMD._text = "#! Title\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "# Title\n\n" assert theMD.theResult == "# Title\n\n"
# Unnumbered # Unnumbered
theMD._theText = "##! Prologue\n" theMD._text = "##! Prologue\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "## Prologue\n\n" assert theMD.theResult == "## Prologue\n\n"
@@ -82,7 +82,7 @@ def testCoreToMarkdown_ConvertFormat(mockGUI):
# Text for GitHub Markdown # Text for GitHub Markdown
theMD.setGitHubMarkdown() theMD.setGitHubMarkdown()
theMD._theText = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n" theMD._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == ( assert theMD.theResult == (
@@ -91,7 +91,7 @@ def testCoreToMarkdown_ConvertFormat(mockGUI):
# Text for Standard Markdown # Text for Standard Markdown
theMD.setStandardMarkdown() theMD.setStandardMarkdown()
theMD._theText = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n" theMD._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == ( assert theMD.theResult == (
@@ -99,50 +99,50 @@ def testCoreToMarkdown_ConvertFormat(mockGUI):
) )
# Text w/Hard Break # Text w/Hard Break
theMD._theText = "Line one \nLine two \nLine three\n" theMD._text = "Line one \nLine two \nLine three\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "Line one \nLine two \nLine three\n\n" assert theMD.theResult == "Line one \nLine two \nLine three\n\n"
# Synopsis # Synopsis
theMD._theText = "%synopsis: The synopsis ...\n" theMD._text = "%synopsis: The synopsis ...\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "" assert theMD.theResult == ""
theMD.setSynopsis(True) theMD.setSynopsis(True)
theMD._theText = "%synopsis: The synopsis ...\n" theMD._text = "%synopsis: The synopsis ...\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "**Synopsis:** The synopsis ...\n\n" assert theMD.theResult == "**Synopsis:** The synopsis ...\n\n"
# Comment # Comment
theMD._theText = "% A comment ...\n" theMD._text = "% A comment ...\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "" assert theMD.theResult == ""
theMD.setComments(True) theMD.setComments(True)
theMD._theText = "% A comment ...\n" theMD._text = "% A comment ...\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "**Comment:** A comment ...\n\n" assert theMD.theResult == "**Comment:** A comment ...\n\n"
# Keywords # Keywords
theMD._theText = "@char: Bod, Jane\n" theMD._text = "@char: Bod, Jane\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "" assert theMD.theResult == ""
theMD.setKeywords(True) theMD.setKeywords(True)
theMD._theText = "@char: Bod, Jane\n" theMD._text = "@char: Bod, Jane\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == "**Characters:** Bod, Jane\n\n" assert theMD.theResult == "**Characters:** Bod, Jane\n\n"
# Multiple Keywords # Multiple Keywords
theMD.setKeywords(True) theMD.setKeywords(True)
theMD._theText = "## Chapter\n\n@pov: Bod\n@plot: Main\n@location: Europe\n\n" theMD._text = "## Chapter\n\n@pov: Bod\n@plot: Main\n@location: Europe\n\n"
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
assert theMD.theResult == ( assert theMD.theResult == (
@@ -169,7 +169,7 @@ def testCoreToMarkdown_ConvertDirect(mockGUI):
# ============== # ==============
# Title # Title
theMD._theTokens = [ theMD._tokens = [
(theMD.T_TITLE, 1, "A Title", None, theMD.A_PBB | theMD.A_CENTRE), (theMD.T_TITLE, 1, "A Title", None, theMD.A_PBB | theMD.A_CENTRE),
(theMD.T_EMPTY, 1, "", None, theMD.A_NONE), (theMD.T_EMPTY, 1, "", None, theMD.A_NONE),
] ]
@@ -177,7 +177,7 @@ def testCoreToMarkdown_ConvertDirect(mockGUI):
assert theMD.theResult == "# A Title\n\n" assert theMD.theResult == "# A Title\n\n"
# Unnumbered # Unnumbered
theMD._theTokens = [ theMD._tokens = [
(theMD.T_UNNUM, 1, "Prologue", None, theMD.A_PBB), (theMD.T_UNNUM, 1, "Prologue", None, theMD.A_PBB),
(theMD.T_EMPTY, 1, "", None, theMD.A_NONE), (theMD.T_EMPTY, 1, "", None, theMD.A_NONE),
] ]
@@ -188,7 +188,7 @@ def testCoreToMarkdown_ConvertDirect(mockGUI):
# ========== # ==========
# Separator # Separator
theMD._theTokens = [ theMD._tokens = [
(theMD.T_SEP, 1, "* * *", None, theMD.A_CENTRE), (theMD.T_SEP, 1, "* * *", None, theMD.A_CENTRE),
(theMD.T_EMPTY, 1, "", None, theMD.A_NONE), (theMD.T_EMPTY, 1, "", None, theMD.A_NONE),
] ]
@@ -196,7 +196,7 @@ def testCoreToMarkdown_ConvertDirect(mockGUI):
assert theMD.theResult == "* * *\n\n" assert theMD.theResult == "* * *\n\n"
# Skip # Skip
theMD._theTokens = [ theMD._tokens = [
(theMD.T_SKIP, 1, "", None, theMD.A_NONE), (theMD.T_SKIP, 1, "", None, theMD.A_NONE),
(theMD.T_EMPTY, 1, "", None, theMD.A_NONE), (theMD.T_EMPTY, 1, "", None, theMD.A_NONE),
] ]
@@ -237,7 +237,7 @@ def testCoreToMarkdown_Complex(mockGUI, fncPath):
] ]
for i in range(len(docText)): for i in range(len(docText)):
theMD._theText = docText[i] theMD._text = docText[i]
theMD.doPreProcessing() theMD.doPreProcessing()
theMD.tokenizeText() theMD.tokenizeText()
theMD.doConvert() theMD.doConvert()
+21 -21
View File
@@ -261,7 +261,7 @@ def testCoreToOdt_Convert(mockGUI):
# ======= # =======
# Header 1 # Header 1
theDoc._theText = "# Title\n" theDoc._text = "# Title\n"
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.initDocument() theDoc.initDocument()
theDoc.doConvert() theDoc.doConvert()
@@ -274,7 +274,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Header 2 # Header 2
theDoc._theText = "## Chapter\n" theDoc._text = "## Chapter\n"
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.initDocument() theDoc.initDocument()
theDoc.doConvert() theDoc.doConvert()
@@ -287,7 +287,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Header 3 # Header 3
theDoc._theText = "### Scene\n" theDoc._text = "### Scene\n"
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.initDocument() theDoc.initDocument()
theDoc.doConvert() theDoc.doConvert()
@@ -300,7 +300,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Header 4 # Header 4
theDoc._theText = "#### Section\n" theDoc._text = "#### Section\n"
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.initDocument() theDoc.initDocument()
theDoc.doConvert() theDoc.doConvert()
@@ -313,7 +313,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Title # Title
theDoc._theText = "#! Title\n" theDoc._text = "#! Title\n"
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.initDocument() theDoc.initDocument()
theDoc.doConvert() theDoc.doConvert()
@@ -326,7 +326,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Unnumbered chapter # Unnumbered chapter
theDoc._theText = "##! Prologue\n" theDoc._text = "##! Prologue\n"
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.initDocument() theDoc.initDocument()
theDoc.doConvert() theDoc.doConvert()
@@ -342,7 +342,7 @@ def testCoreToOdt_Convert(mockGUI):
# ========== # ==========
# Nested Text # Nested Text
theDoc._theText = "Some ~~nested **bold** and _italics_ text~~ text." theDoc._text = "Some ~~nested **bold** and _italics_ text~~ text."
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.initDocument() theDoc.initDocument()
theDoc.doConvert() theDoc.doConvert()
@@ -360,7 +360,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Hard Break # Hard Break
theDoc._theText = "Some text.\nNext line\n" theDoc._text = "Some text.\nNext line\n"
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.initDocument() theDoc.initDocument()
theDoc.doConvert() theDoc.doConvert()
@@ -373,7 +373,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Tab # Tab
theDoc._theText = "\tItem 1\tItem 2\n" theDoc._text = "\tItem 1\tItem 2\n"
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.initDocument() theDoc.initDocument()
theDoc.doConvert() theDoc.doConvert()
@@ -386,7 +386,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Tab in Format # Tab in Format
theDoc._theText = "Some **bold\ttext**" theDoc._text = "Some **bold\ttext**"
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.initDocument() theDoc.initDocument()
theDoc.doConvert() theDoc.doConvert()
@@ -400,7 +400,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Multiple Spaces # Multiple Spaces
theDoc._theText = ( theDoc._text = (
"### Scene\n\n" "### Scene\n\n"
"Hello World\n\n" "Hello World\n\n"
"Hello World\n\n" "Hello World\n\n"
@@ -421,7 +421,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Synopsis, Comment, Keywords # Synopsis, Comment, Keywords
theDoc._theText = ( theDoc._text = (
"### Scene\n\n" "### Scene\n\n"
"@pov: Jane\n\n" "@pov: Jane\n\n"
"% synopsis: So it begins\n\n" "% synopsis: So it begins\n\n"
@@ -448,7 +448,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Scene Separator # Scene Separator
theDoc._theText = "### Scene One\n\nText\n\n### Scene Two\n\nText" theDoc._text = "### Scene One\n\nText\n\n### Scene Two\n\nText"
theDoc.setSceneFormat("* * *", False) theDoc.setSceneFormat("* * *", False)
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.doHeaders() theDoc.doHeaders()
@@ -466,7 +466,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Scene Break # Scene Break
theDoc._theText = "### Scene One\n\nText\n\n### Scene Two\n\nText" theDoc._text = "### Scene One\n\nText\n\n### Scene Two\n\nText"
theDoc.setSceneFormat("", False) theDoc.setSceneFormat("", False)
theDoc.tokenizeText() theDoc.tokenizeText()
theDoc.doHeaders() theDoc.doHeaders()
@@ -484,7 +484,7 @@ def testCoreToOdt_Convert(mockGUI):
) )
# Paragraph Styles # Paragraph Styles
theDoc._theText = ( theDoc._text = (
"### Scene\n\n" "### Scene\n\n"
"@pov: Jane\n" "@pov: Jane\n"
"@char: John\n" "@char: John\n"
@@ -526,7 +526,7 @@ def testCoreToOdt_Convert(mockGUI):
assert getStyle("P8")._pAttr["margin-right"] == ["fo", "1.693cm"] assert getStyle("P8")._pAttr["margin-right"] == ["fo", "1.693cm"]
# Justified # Justified
theDoc._theText = ( theDoc._text = (
"### Scene\n\n" "### Scene\n\n"
"Regular paragraph\n\n" "Regular paragraph\n\n"
"with\nbreak\n\n" "with\nbreak\n\n"
@@ -549,7 +549,7 @@ def testCoreToOdt_Convert(mockGUI):
assert getStyle("P9")._pAttr["text-align"] == ["fo", "left"] assert getStyle("P9")._pAttr["text-align"] == ["fo", "left"]
# Page Breaks # Page Breaks
theDoc._theText = ( theDoc._text = (
"## Chapter One\n\n" "## Chapter One\n\n"
"Text\n\n" "Text\n\n"
"## Chapter Two\n\n" "## Chapter Two\n\n"
@@ -584,7 +584,7 @@ def testCoreToOdt_ConvertDirect(mockGUI):
# Justified # Justified
theDoc = ToOdt(theProject, isFlat=True) theDoc = ToOdt(theProject, isFlat=True)
theDoc._theTokens = [ theDoc._tokens = [
(theDoc.T_TEXT, 1, "This is a paragraph", [], theDoc.A_JUSTIFY), (theDoc.T_TEXT, 1, "This is a paragraph", [], theDoc.A_JUSTIFY),
(theDoc.T_EMPTY, 1, "", None, theDoc.A_NONE), (theDoc.T_EMPTY, 1, "", None, theDoc.A_NONE),
] ]
@@ -605,7 +605,7 @@ def testCoreToOdt_ConvertDirect(mockGUI):
# Page Break After # Page Break After
theDoc = ToOdt(theProject, isFlat=True) theDoc = ToOdt(theProject, isFlat=True)
theDoc._theTokens = [ theDoc._tokens = [
(theDoc.T_TEXT, 1, "This is a paragraph", [], theDoc.A_PBA), (theDoc.T_TEXT, 1, "This is a paragraph", [], theDoc.A_PBA),
(theDoc.T_EMPTY, 1, "", None, theDoc.A_NONE), (theDoc.T_EMPTY, 1, "", None, theDoc.A_NONE),
] ]
@@ -643,7 +643,7 @@ def testCoreToOdt_SaveFlat(mockGUI, fncPath, tstPaths):
assert theDoc.setLanguage("nb_NO") is True assert theDoc.setLanguage("nb_NO") is True
theDoc.setColourHeaders(True) theDoc.setColourHeaders(True)
theDoc._theText = ( theDoc._text = (
"## Chapter One\n\n" "## Chapter One\n\n"
"Text\n\n" "Text\n\n"
"## Chapter Two\n\n" "## Chapter Two\n\n"
@@ -680,7 +680,7 @@ def testCoreToOdt_SaveFull(mockGUI, fncPath, tstPaths):
theDoc = ToOdt(theProject, isFlat=False) theDoc = ToOdt(theProject, isFlat=False)
theDoc._isNovel = True theDoc._isNovel = True
theDoc._theText = ( theDoc._text = (
"## Chapter One\n\n" "## Chapter One\n\n"
"Text\n\n" "Text\n\n"
"## Chapter Two\n\n" "## Chapter Two\n\n"