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