Fix title page break issue and add test coverage
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
"Short Description": "Short Description",
|
"Short Description": "Short Description",
|
||||||
"Footnotes": "Footnotes",
|
"Footnotes": "Footnotes",
|
||||||
"Comment": "Comment",
|
"Comment": "Comment",
|
||||||
"Note": "Note",
|
"Notes": "Notes",
|
||||||
"Tag": "Tag",
|
"Tag": "Tag",
|
||||||
"Point of View": "Point of View",
|
"Point of View": "Point of View",
|
||||||
"Focus": "Focus",
|
"Focus": "Focus",
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ SETTINGS_TEMPLATE: dict[str, tuple[type, str | int | float | bool]] = {
|
|||||||
"headings.centerPart": (bool, True),
|
"headings.centerPart": (bool, True),
|
||||||
"headings.centerChapter": (bool, False),
|
"headings.centerChapter": (bool, False),
|
||||||
"headings.centerScene": (bool, False),
|
"headings.centerScene": (bool, False),
|
||||||
"headings.breakTitle": (bool, True),
|
"headings.breakTitle": (bool, False),
|
||||||
"headings.breakPart": (bool, True),
|
"headings.breakPart": (bool, True),
|
||||||
"headings.breakChapter": (bool, True),
|
"headings.breakChapter": (bool, True),
|
||||||
"headings.breakScene": (bool, False),
|
"headings.breakScene": (bool, False),
|
||||||
|
|||||||
@@ -267,8 +267,8 @@ class NWBuildDocument:
|
|||||||
self._build.getBool("headings.hideSection")
|
self._build.getBool("headings.hideSection")
|
||||||
)
|
)
|
||||||
bldObj.setTitleStyle(
|
bldObj.setTitleStyle(
|
||||||
self._build.getBool("headings.centerPart"),
|
self._build.getBool("headings.centerTitle"),
|
||||||
self._build.getBool("headings.breakPart")
|
self._build.getBool("headings.breakTitle")
|
||||||
)
|
)
|
||||||
bldObj.setPartitionStyle(
|
bldObj.setPartitionStyle(
|
||||||
self._build.getBool("headings.centerPart"),
|
self._build.getBool("headings.centerPart"),
|
||||||
|
|||||||
@@ -452,20 +452,22 @@ class Tokenizer(ABC):
|
|||||||
self._text = ""
|
self._text = ""
|
||||||
self._handle = None
|
self._handle = None
|
||||||
|
|
||||||
if (tItem := self._project.tree[tHandle]) and tItem.isRootType():
|
if (item := self._project.tree[tHandle]) and item.isRootType():
|
||||||
self._handle = tHandle
|
self._handle = tHandle
|
||||||
|
style = BlockFmt.CENTRE
|
||||||
if self._isFirst:
|
if self._isFirst:
|
||||||
textAlign = BlockFmt.CENTRE
|
|
||||||
self._isFirst = False
|
self._isFirst = False
|
||||||
else:
|
else:
|
||||||
textAlign = BlockFmt.PBB | BlockFmt.CENTRE
|
style |= BlockFmt.PBB
|
||||||
|
|
||||||
trNotes = self._localLookup("Notes")
|
title = item.itemName
|
||||||
title = f"{trNotes}: {tItem.itemName}"
|
if not item.isNovelLike():
|
||||||
self._blocks = []
|
notes = self._localLookup("Notes")
|
||||||
self._blocks.append((
|
title = f"{notes}: {title}"
|
||||||
BlockTyp.TITLE, f"{self._handle}:T0001", title, [], textAlign
|
|
||||||
))
|
self._blocks = [(
|
||||||
|
BlockTyp.TITLE, f"{self._handle}:T0001", title, [], style
|
||||||
|
)]
|
||||||
if self._keepRaw:
|
if self._keepRaw:
|
||||||
self._raw.append(f"#! {title}\n\n")
|
self._raw.append(f"#! {title}\n\n")
|
||||||
|
|
||||||
@@ -531,7 +533,7 @@ class Tokenizer(ABC):
|
|||||||
|
|
||||||
nHead = 0
|
nHead = 0
|
||||||
breakNext = False
|
breakNext = False
|
||||||
tmpMarkdown = []
|
rawText = []
|
||||||
tHandle = self._handle or ""
|
tHandle = self._handle or ""
|
||||||
tBlocks: list[T_Block] = [B_EMPTY]
|
tBlocks: list[T_Block] = [B_EMPTY]
|
||||||
for bLine in text.splitlines():
|
for bLine in text.splitlines():
|
||||||
@@ -542,7 +544,7 @@ class Tokenizer(ABC):
|
|||||||
if not sLine:
|
if not sLine:
|
||||||
tBlocks.append(B_EMPTY)
|
tBlocks.append(B_EMPTY)
|
||||||
if keepRaw:
|
if keepRaw:
|
||||||
tmpMarkdown.append("\n")
|
rawText.append("\n")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if breakNext:
|
if breakNext:
|
||||||
@@ -608,13 +610,13 @@ class Tokenizer(ABC):
|
|||||||
BlockTyp.COMMENT, "", tLine, tFmt, sAlign
|
BlockTyp.COMMENT, "", tLine, tFmt, sAlign
|
||||||
))
|
))
|
||||||
if keepRaw:
|
if keepRaw:
|
||||||
tmpMarkdown.append(f"{aLine}\n")
|
rawText.append(f"{aLine}\n")
|
||||||
|
|
||||||
elif cStyle == nwComment.FOOTNOTE:
|
elif cStyle == nwComment.FOOTNOTE:
|
||||||
tLine, tFmt = self._extractFormats(cText, skip=TextFmt.FNOTE)
|
tLine, tFmt = self._extractFormats(cText, skip=TextFmt.FNOTE)
|
||||||
self._footnotes[f"{tHandle}:{cKey}"] = (tLine, tFmt)
|
self._footnotes[f"{tHandle}:{cKey}"] = (tLine, tFmt)
|
||||||
if keepRaw:
|
if keepRaw:
|
||||||
tmpMarkdown.append(f"{aLine}\n")
|
rawText.append(f"{aLine}\n")
|
||||||
|
|
||||||
elif aLine.startswith("@"):
|
elif aLine.startswith("@"):
|
||||||
# Keywords
|
# Keywords
|
||||||
@@ -629,7 +631,7 @@ class Tokenizer(ABC):
|
|||||||
BlockTyp.KEYWORD, tTag[1:], tLine, tFmt, sAlign
|
BlockTyp.KEYWORD, tTag[1:], tLine, tFmt, sAlign
|
||||||
))
|
))
|
||||||
if keepRaw:
|
if keepRaw:
|
||||||
tmpMarkdown.append(f"{aLine}\n")
|
rawText.append(f"{aLine}\n")
|
||||||
|
|
||||||
elif aLine.startswith(("# ", "#! ")):
|
elif aLine.startswith(("# ", "#! ")):
|
||||||
# Title or Partition Headings
|
# Title or Partition Headings
|
||||||
@@ -665,7 +667,7 @@ class Tokenizer(ABC):
|
|||||||
tType, f"{tHandle}:T{nHead:04d}", tText, [], tStyle
|
tType, f"{tHandle}:T{nHead:04d}", tText, [], tStyle
|
||||||
))
|
))
|
||||||
if keepRaw:
|
if keepRaw:
|
||||||
tmpMarkdown.append(f"{aLine}\n")
|
rawText.append(f"{aLine}\n")
|
||||||
|
|
||||||
elif aLine.startswith(("## ", "##! ")):
|
elif aLine.startswith(("## ", "##! ")):
|
||||||
# (Unnumbered) Chapter Headings
|
# (Unnumbered) Chapter Headings
|
||||||
@@ -700,7 +702,7 @@ class Tokenizer(ABC):
|
|||||||
tType, f"{tHandle}:T{nHead:04d}", tText, [], tStyle
|
tType, f"{tHandle}:T{nHead:04d}", tText, [], tStyle
|
||||||
))
|
))
|
||||||
if keepRaw:
|
if keepRaw:
|
||||||
tmpMarkdown.append(f"{aLine}\n")
|
rawText.append(f"{aLine}\n")
|
||||||
|
|
||||||
elif aLine.startswith(("### ", "###! ")):
|
elif aLine.startswith(("### ", "###! ")):
|
||||||
# (Alternative) Scene Headings
|
# (Alternative) Scene Headings
|
||||||
@@ -741,7 +743,7 @@ class Tokenizer(ABC):
|
|||||||
tType, f"{tHandle}:T{nHead:04d}", tText, [], tStyle
|
tType, f"{tHandle}:T{nHead:04d}", tText, [], tStyle
|
||||||
))
|
))
|
||||||
if keepRaw:
|
if keepRaw:
|
||||||
tmpMarkdown.append(f"{aLine}\n")
|
rawText.append(f"{aLine}\n")
|
||||||
|
|
||||||
elif aLine.startswith("#### "):
|
elif aLine.startswith("#### "):
|
||||||
# Section Headings
|
# Section Headings
|
||||||
@@ -771,7 +773,7 @@ class Tokenizer(ABC):
|
|||||||
tType, f"{tHandle}:T{nHead:04d}", tText, [], tStyle
|
tType, f"{tHandle}:T{nHead:04d}", tText, [], tStyle
|
||||||
))
|
))
|
||||||
if keepRaw:
|
if keepRaw:
|
||||||
tmpMarkdown.append(f"{aLine}\n")
|
rawText.append(f"{aLine}\n")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Text Lines
|
# Text Lines
|
||||||
@@ -819,7 +821,7 @@ class Tokenizer(ABC):
|
|||||||
BlockTyp.TEXT, "", tLine, tFmt, sAlign
|
BlockTyp.TEXT, "", tLine, tFmt, sAlign
|
||||||
))
|
))
|
||||||
if keepRaw:
|
if keepRaw:
|
||||||
tmpMarkdown.append(f"{aLine}\n")
|
rawText.append(f"{aLine}\n")
|
||||||
|
|
||||||
# If we have content, turn off the first page flag
|
# If we have content, turn off the first page flag
|
||||||
if self._isFirst and len(tBlocks) > 1:
|
if self._isFirst and len(tBlocks) > 1:
|
||||||
@@ -835,8 +837,8 @@ class Tokenizer(ABC):
|
|||||||
# Always add an empty line at the end of the file
|
# Always add an empty line at the end of the file
|
||||||
tBlocks.append(B_EMPTY)
|
tBlocks.append(B_EMPTY)
|
||||||
if keepRaw:
|
if keepRaw:
|
||||||
tmpMarkdown.append("\n")
|
rawText.append("\n")
|
||||||
self._raw.append("".join(tmpMarkdown))
|
self._raw.append("".join(rawText))
|
||||||
|
|
||||||
# Second Pass
|
# Second Pass
|
||||||
# ===========
|
# ===========
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
%%~name: Title Page
|
%%~name: Title Page
|
||||||
%%~path: 7031beac91f75/53b69b83cdafc
|
%%~path: 7031beac91f75/53b69b83cdafc
|
||||||
%%~kind: NOVEL/DOCUMENT
|
%%~kind: NOVEL/DOCUMENT
|
||||||
%%~hash: c5dc35d18ecb074a9e41a1410d1bff8021cf0a5b
|
%%~hash: 4072adb6d21ff877577f033f19714d9bd01396f3
|
||||||
%%~date: Unknown/2023-08-25 16:51:52
|
%%~date: Unknown/2024-10-24 16:25:44
|
||||||
|
|
||||||
|
Jane Smith[br]
|
||||||
|
42 Main Street[br]
|
||||||
|
1234 Capital City <<
|
||||||
|
|
||||||
|
[vspace:5]
|
||||||
|
|
||||||
#! My Novel
|
#! My Novel
|
||||||
|
|
||||||
>> **By Jane Smith** <<
|
>> **By Jane Smith** <<
|
||||||
|
|
||||||
>> This is the title page. <<
|
>> This is the title page. <<
|
||||||
>> It should be the first document of the project. <<
|
>> It should be the first document of the project. <<
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<novelWriterXML appVersion="2.6a2" hexVersion="0x020600a2" fileVersion="1.5" fileRevision="4" timeStamp="2024-10-23 17:41:09">
|
<novelWriterXML appVersion="2.6a2" hexVersion="0x020600a2" fileVersion="1.5" fileRevision="4" timeStamp="2024-10-24 16:26:12">
|
||||||
<project id="e2be99af-f9bf-4403-857a-c3d1ac25abea" saveCount="2074" autoCount="277" editTime="93039">
|
<project id="e2be99af-f9bf-4403-857a-c3d1ac25abea" saveCount="2077" autoCount="279" editTime="93511">
|
||||||
<name>Sample Project</name>
|
<name>Sample Project</name>
|
||||||
<author>Jane Smith</author>
|
<author>Jane Smith</author>
|
||||||
</project>
|
</project>
|
||||||
@@ -36,13 +36,13 @@
|
|||||||
<entry key="i56be10" count="1" red="220" green="138" blue="221" shape="BLOCK_4">Main</entry>
|
<entry key="i56be10" count="1" red="220" green="138" blue="221" shape="BLOCK_4">Main</entry>
|
||||||
</importance>
|
</importance>
|
||||||
</settings>
|
</settings>
|
||||||
<content items="31" novelWords="996" notesWords="416">
|
<content items="31" novelWords="1004" notesWords="416">
|
||||||
<item handle="7031beac91f75" parent="None" root="7031beac91f75" order="0" type="ROOT" class="NOVEL">
|
<item handle="7031beac91f75" parent="None" root="7031beac91f75" order="0" type="ROOT" class="NOVEL">
|
||||||
<meta expanded="yes" />
|
<meta expanded="yes" />
|
||||||
<name status="sc24b8f" import="ia857f0">Novel</name>
|
<name status="sc24b8f" import="ia857f0">Novel</name>
|
||||||
</item>
|
</item>
|
||||||
<item handle="53b69b83cdafc" parent="7031beac91f75" root="7031beac91f75" order="0" type="FILE" class="NOVEL" layout="DOCUMENT">
|
<item handle="53b69b83cdafc" parent="7031beac91f75" root="7031beac91f75" order="0" type="FILE" class="NOVEL" layout="DOCUMENT">
|
||||||
<meta expanded="no" heading="H1" charCount="95" wordCount="19" paraCount="2" cursorPos="31" />
|
<meta expanded="no" heading="H1" charCount="136" wordCount="27" paraCount="3" cursorPos="69" />
|
||||||
<name status="sc24b8f" import="ia857f0" active="yes">Title Page</name>
|
<name status="sc24b8f" import="ia857f0" active="yes">Title Page</name>
|
||||||
</item>
|
</item>
|
||||||
<item handle="974e400180a99" parent="7031beac91f75" root="7031beac91f75" order="1" type="FILE" class="NOVEL" layout="DOCUMENT">
|
<item handle="974e400180a99" parent="7031beac91f75" root="7031beac91f75" order="1" type="FILE" class="NOVEL" layout="DOCUMENT">
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
<name status="sf24ce6" import="ia857f0" active="yes">Chapter One</name>
|
<name status="sf24ce6" import="ia857f0" active="yes">Chapter One</name>
|
||||||
</item>
|
</item>
|
||||||
<item handle="636b6aa9b697b" parent="6a2d6d5f4f401" root="7031beac91f75" order="0" type="FILE" class="NOVEL" layout="DOCUMENT">
|
<item handle="636b6aa9b697b" parent="6a2d6d5f4f401" root="7031beac91f75" order="0" type="FILE" class="NOVEL" layout="DOCUMENT">
|
||||||
<meta expanded="no" heading="H3" charCount="2953" wordCount="520" paraCount="15" cursorPos="66" />
|
<meta expanded="no" heading="H3" charCount="2937" wordCount="520" paraCount="15" cursorPos="4" />
|
||||||
<name status="s90e6c9" import="ia857f0" active="yes">Making a Scene</name>
|
<name status="s90e6c9" import="ia857f0" active="yes">Making a Scene</name>
|
||||||
</item>
|
</item>
|
||||||
<item handle="bc0cbd2a407f3" parent="6a2d6d5f4f401" root="7031beac91f75" order="1" type="FILE" class="NOVEL" layout="DOCUMENT">
|
<item handle="bc0cbd2a407f3" parent="6a2d6d5f4f401" root="7031beac91f75" order="1" type="FILE" class="NOVEL" layout="DOCUMENT">
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
<name status="s90e6c9" import="ia857f0" active="yes">Another Scene</name>
|
<name status="s90e6c9" import="ia857f0" active="yes">Another Scene</name>
|
||||||
</item>
|
</item>
|
||||||
<item handle="ba8a28a246524" parent="7031beac91f75" root="7031beac91f75" order="4" type="FILE" class="NOVEL" layout="DOCUMENT">
|
<item handle="ba8a28a246524" parent="7031beac91f75" root="7031beac91f75" order="4" type="FILE" class="NOVEL" layout="DOCUMENT">
|
||||||
<meta expanded="no" heading="H2" charCount="617" wordCount="101" paraCount="3" cursorPos="357" />
|
<meta expanded="no" heading="H2" charCount="617" wordCount="101" paraCount="3" cursorPos="1182" />
|
||||||
<name status="s78ea90" import="ia857f0" active="yes">Interlude</name>
|
<name status="s78ea90" import="ia857f0" active="yes">Interlude</name>
|
||||||
</item>
|
</item>
|
||||||
<item handle="96b68994dfa3d" parent="7031beac91f75" root="7031beac91f75" order="5" type="FILE" class="NOVEL" layout="NOTE">
|
<item handle="96b68994dfa3d" parent="7031beac91f75" root="7031beac91f75" order="5" type="FILE" class="NOVEL" layout="NOTE">
|
||||||
|
|||||||
@@ -421,8 +421,8 @@ def testFmtToken_HeaderFormat(mockGUI):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testFmtToken_HeaderStyle(mockGUI):
|
def testFmtToken_HeaderStyleNone(mockGUI):
|
||||||
"""Test the styling of headers in the Tokenizer class."""
|
"""Test header styling disabled."""
|
||||||
project = NWProject()
|
project = NWProject()
|
||||||
tokens = BareTokenizer(project)
|
tokens = BareTokenizer(project)
|
||||||
|
|
||||||
@@ -432,13 +432,12 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
tokens.tokenizeText()
|
tokens.tokenizeText()
|
||||||
return tokens._blocks[0][4]
|
return tokens._blocks[0][4]
|
||||||
|
|
||||||
# No Styles
|
tokens.setTitleStyle(False, False)
|
||||||
# =========
|
|
||||||
|
|
||||||
tokens.setPartitionStyle(False, False)
|
tokens.setPartitionStyle(False, False)
|
||||||
tokens.setChapterStyle(False, False)
|
tokens.setChapterStyle(False, False)
|
||||||
tokens.setSceneStyle(False, False)
|
tokens.setSceneStyle(False, False)
|
||||||
|
|
||||||
|
assert tokens._titleStyle == BlockFmt.NONE
|
||||||
assert tokens._partStyle == BlockFmt.NONE
|
assert tokens._partStyle == BlockFmt.NONE
|
||||||
assert tokens._chapterStyle == BlockFmt.NONE
|
assert tokens._chapterStyle == BlockFmt.NONE
|
||||||
assert tokens._sceneStyle == BlockFmt.NONE
|
assert tokens._sceneStyle == BlockFmt.NONE
|
||||||
@@ -451,7 +450,7 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("#! My Novel\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
||||||
|
|
||||||
# First Document is True
|
# First Document is True
|
||||||
@@ -459,7 +458,7 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", True) == BlockFmt.NONE
|
assert processStyle("## Chapter\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("### Scene\n", True) == BlockFmt.NONE
|
assert processStyle("### Scene\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("#### Section\n", True) == BlockFmt.NONE
|
assert processStyle("#### Section\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", True) == BlockFmt.CENTRE
|
assert processStyle("#! My Novel\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
||||||
|
|
||||||
# Note Docs
|
# Note Docs
|
||||||
@@ -470,7 +469,7 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("#! My Novel\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
||||||
|
|
||||||
# First Document is True
|
# First Document is True
|
||||||
@@ -478,16 +477,28 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", True) == BlockFmt.NONE
|
assert processStyle("## Chapter\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("### Scene\n", True) == BlockFmt.NONE
|
assert processStyle("### Scene\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("#### Section\n", True) == BlockFmt.NONE
|
assert processStyle("#### Section\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", True) == BlockFmt.CENTRE
|
assert processStyle("#! My Novel\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
||||||
|
|
||||||
# Center Headers
|
|
||||||
# ==============
|
|
||||||
|
|
||||||
|
@pytest.mark.core
|
||||||
|
def testFmtToken_HeaderStyleCenter(mockGUI):
|
||||||
|
"""Test header styling centred."""
|
||||||
|
project = NWProject()
|
||||||
|
tokens = BareTokenizer(project)
|
||||||
|
|
||||||
|
def processStyle(text: str, first: bool) -> BlockFmt:
|
||||||
|
tokens._text = text
|
||||||
|
tokens._isFirst = first
|
||||||
|
tokens.tokenizeText()
|
||||||
|
return tokens._blocks[0][4]
|
||||||
|
|
||||||
|
tokens.setTitleStyle(True, False)
|
||||||
tokens.setPartitionStyle(True, False)
|
tokens.setPartitionStyle(True, False)
|
||||||
tokens.setChapterStyle(True, False)
|
tokens.setChapterStyle(True, False)
|
||||||
tokens.setSceneStyle(True, False)
|
tokens.setSceneStyle(True, False)
|
||||||
|
|
||||||
|
assert tokens._titleStyle == BlockFmt.CENTRE
|
||||||
assert tokens._partStyle == BlockFmt.CENTRE
|
assert tokens._partStyle == BlockFmt.CENTRE
|
||||||
assert tokens._chapterStyle == BlockFmt.CENTRE
|
assert tokens._chapterStyle == BlockFmt.CENTRE
|
||||||
assert tokens._sceneStyle == BlockFmt.CENTRE
|
assert tokens._sceneStyle == BlockFmt.CENTRE
|
||||||
@@ -500,7 +511,7 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", False) == BlockFmt.CENTRE
|
assert processStyle("## Chapter\n", False) == BlockFmt.CENTRE
|
||||||
assert processStyle("### Scene\n", False) == BlockFmt.CENTRE
|
assert processStyle("### Scene\n", False) == BlockFmt.CENTRE
|
||||||
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE
|
||||||
assert processStyle("##! Prologue\n", False) == BlockFmt.CENTRE
|
assert processStyle("##! Prologue\n", False) == BlockFmt.CENTRE
|
||||||
|
|
||||||
# First Document is True
|
# First Document is True
|
||||||
@@ -519,7 +530,7 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE
|
||||||
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
||||||
|
|
||||||
# First Document is True
|
# First Document is True
|
||||||
@@ -530,13 +541,25 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("#! My Novel\n", True) == BlockFmt.CENTRE
|
assert processStyle("#! My Novel\n", True) == BlockFmt.CENTRE
|
||||||
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
||||||
|
|
||||||
# Page Break Headers
|
|
||||||
# ==================
|
|
||||||
|
|
||||||
|
@pytest.mark.core
|
||||||
|
def testFmtToken_HeaderStylePageBreak(mockGUI):
|
||||||
|
"""Test header styling page break."""
|
||||||
|
project = NWProject()
|
||||||
|
tokens = BareTokenizer(project)
|
||||||
|
|
||||||
|
def processStyle(text: str, first: bool) -> BlockFmt:
|
||||||
|
tokens._text = text
|
||||||
|
tokens._isFirst = first
|
||||||
|
tokens.tokenizeText()
|
||||||
|
return tokens._blocks[0][4]
|
||||||
|
|
||||||
|
tokens.setTitleStyle(False, True)
|
||||||
tokens.setPartitionStyle(False, True)
|
tokens.setPartitionStyle(False, True)
|
||||||
tokens.setChapterStyle(False, True)
|
tokens.setChapterStyle(False, True)
|
||||||
tokens.setSceneStyle(False, True)
|
tokens.setSceneStyle(False, True)
|
||||||
|
|
||||||
|
assert tokens._titleStyle == BlockFmt.PBB
|
||||||
assert tokens._partStyle == BlockFmt.PBB
|
assert tokens._partStyle == BlockFmt.PBB
|
||||||
assert tokens._chapterStyle == BlockFmt.PBB
|
assert tokens._chapterStyle == BlockFmt.PBB
|
||||||
assert tokens._sceneStyle == BlockFmt.PBB
|
assert tokens._sceneStyle == BlockFmt.PBB
|
||||||
@@ -549,7 +572,7 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", False) == BlockFmt.PBB
|
assert processStyle("## Chapter\n", False) == BlockFmt.PBB
|
||||||
assert processStyle("### Scene\n", False) == BlockFmt.PBB
|
assert processStyle("### Scene\n", False) == BlockFmt.PBB
|
||||||
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("#! My Novel\n", False) == BlockFmt.PBB
|
||||||
assert processStyle("##! Prologue\n", False) == BlockFmt.PBB
|
assert processStyle("##! Prologue\n", False) == BlockFmt.PBB
|
||||||
|
|
||||||
# First Document is True
|
# First Document is True
|
||||||
@@ -557,7 +580,7 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", True) == BlockFmt.NONE
|
assert processStyle("## Chapter\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("### Scene\n", True) == BlockFmt.NONE
|
assert processStyle("### Scene\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("#### Section\n", True) == BlockFmt.NONE
|
assert processStyle("#### Section\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", True) == BlockFmt.CENTRE
|
assert processStyle("#! My Novel\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
||||||
|
|
||||||
# Note Docs
|
# Note Docs
|
||||||
@@ -568,7 +591,7 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("#! My Novel\n", False) == BlockFmt.PBB
|
||||||
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
||||||
|
|
||||||
# First Document is True
|
# First Document is True
|
||||||
@@ -576,16 +599,28 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", True) == BlockFmt.NONE
|
assert processStyle("## Chapter\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("### Scene\n", True) == BlockFmt.NONE
|
assert processStyle("### Scene\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("#### Section\n", True) == BlockFmt.NONE
|
assert processStyle("#### Section\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", True) == BlockFmt.CENTRE
|
assert processStyle("#! My Novel\n", True) == BlockFmt.NONE
|
||||||
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
||||||
|
|
||||||
# Page Break and Centre Headers
|
|
||||||
# =============================
|
|
||||||
|
|
||||||
|
@pytest.mark.core
|
||||||
|
def testFmtToken_HeaderStylePageBreakCenter(mockGUI):
|
||||||
|
"""Test header styling page break and centred."""
|
||||||
|
project = NWProject()
|
||||||
|
tokens = BareTokenizer(project)
|
||||||
|
|
||||||
|
def processStyle(text: str, first: bool) -> BlockFmt:
|
||||||
|
tokens._text = text
|
||||||
|
tokens._isFirst = first
|
||||||
|
tokens.tokenizeText()
|
||||||
|
return tokens._blocks[0][4]
|
||||||
|
|
||||||
|
tokens.setTitleStyle(True, True)
|
||||||
tokens.setPartitionStyle(True, True)
|
tokens.setPartitionStyle(True, True)
|
||||||
tokens.setChapterStyle(True, True)
|
tokens.setChapterStyle(True, True)
|
||||||
tokens.setSceneStyle(True, True)
|
tokens.setSceneStyle(True, True)
|
||||||
|
|
||||||
|
assert tokens._titleStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
assert tokens._partStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
assert tokens._partStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
assert tokens._chapterStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
assert tokens._chapterStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
assert tokens._sceneStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
assert tokens._sceneStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
@@ -628,15 +663,46 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("#! My Novel\n", True) == BlockFmt.CENTRE
|
assert processStyle("#! My Novel\n", True) == BlockFmt.CENTRE
|
||||||
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", True) == BlockFmt.NONE
|
||||||
|
|
||||||
# Check Separation
|
|
||||||
# ================
|
@pytest.mark.core
|
||||||
|
def testFmtToken_HeaderStyleSeparation(mockGUI):
|
||||||
|
"""Test header styling separation."""
|
||||||
|
project = NWProject()
|
||||||
|
tokens = BareTokenizer(project)
|
||||||
|
|
||||||
|
def processStyle(text: str, first: bool) -> BlockFmt:
|
||||||
|
tokens._text = text
|
||||||
|
tokens._isFirst = first
|
||||||
|
tokens.tokenizeText()
|
||||||
|
return tokens._blocks[0][4]
|
||||||
|
|
||||||
tokens._isNovel = True
|
tokens._isNovel = True
|
||||||
|
|
||||||
# Title Styles
|
# Title Styles
|
||||||
|
tokens.setTitleStyle(True, True)
|
||||||
|
tokens.setPartitionStyle(False, False)
|
||||||
|
tokens.setChapterStyle(False, False)
|
||||||
|
tokens.setSceneStyle(False, False)
|
||||||
|
|
||||||
|
assert tokens._titleStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
|
assert tokens._partStyle == BlockFmt.NONE
|
||||||
|
assert tokens._chapterStyle == BlockFmt.NONE
|
||||||
|
assert tokens._sceneStyle == BlockFmt.NONE
|
||||||
|
|
||||||
|
assert processStyle("# Title\n", False) == BlockFmt.NONE
|
||||||
|
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
||||||
|
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
||||||
|
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
||||||
|
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
|
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
||||||
|
|
||||||
|
# Partition Styles
|
||||||
|
tokens.setTitleStyle(False, False)
|
||||||
tokens.setPartitionStyle(True, True)
|
tokens.setPartitionStyle(True, True)
|
||||||
tokens.setChapterStyle(False, False)
|
tokens.setChapterStyle(False, False)
|
||||||
tokens.setSceneStyle(False, False)
|
tokens.setSceneStyle(False, False)
|
||||||
|
|
||||||
|
assert tokens._titleStyle == BlockFmt.NONE
|
||||||
assert tokens._partStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
assert tokens._partStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
assert tokens._chapterStyle == BlockFmt.NONE
|
assert tokens._chapterStyle == BlockFmt.NONE
|
||||||
assert tokens._sceneStyle == BlockFmt.NONE
|
assert tokens._sceneStyle == BlockFmt.NONE
|
||||||
@@ -645,14 +711,16 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("#! My Novel\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
||||||
|
|
||||||
# Chapter Styles
|
# Chapter Styles
|
||||||
|
tokens.setTitleStyle(False, False)
|
||||||
tokens.setPartitionStyle(False, False)
|
tokens.setPartitionStyle(False, False)
|
||||||
tokens.setChapterStyle(True, True)
|
tokens.setChapterStyle(True, True)
|
||||||
tokens.setSceneStyle(False, False)
|
tokens.setSceneStyle(False, False)
|
||||||
|
|
||||||
|
assert tokens._titleStyle == BlockFmt.NONE
|
||||||
assert tokens._partStyle == BlockFmt.NONE
|
assert tokens._partStyle == BlockFmt.NONE
|
||||||
assert tokens._chapterStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
assert tokens._chapterStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
assert tokens._sceneStyle == BlockFmt.NONE
|
assert tokens._sceneStyle == BlockFmt.NONE
|
||||||
@@ -661,14 +729,16 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("## Chapter\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
assert processStyle("### Scene\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("#! My Novel\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("##! Prologue\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("##! Prologue\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
|
|
||||||
# Scene Styles
|
# Scene Styles
|
||||||
|
tokens.setTitleStyle(False, False)
|
||||||
tokens.setPartitionStyle(False, False)
|
tokens.setPartitionStyle(False, False)
|
||||||
tokens.setChapterStyle(False, False)
|
tokens.setChapterStyle(False, False)
|
||||||
tokens.setSceneStyle(True, True)
|
tokens.setSceneStyle(True, True)
|
||||||
|
|
||||||
|
assert tokens._titleStyle == BlockFmt.NONE
|
||||||
assert tokens._partStyle == BlockFmt.NONE
|
assert tokens._partStyle == BlockFmt.NONE
|
||||||
assert tokens._chapterStyle == BlockFmt.NONE
|
assert tokens._chapterStyle == BlockFmt.NONE
|
||||||
assert tokens._sceneStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
assert tokens._sceneStyle == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
@@ -677,7 +747,7 @@ def testFmtToken_HeaderStyle(mockGUI):
|
|||||||
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
assert processStyle("## Chapter\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("### Scene\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("### Scene\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
||||||
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
assert processStyle("#### Section\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("#! My Novel\n", False) == BlockFmt.CENTRE | BlockFmt.PBB
|
assert processStyle("#! My Novel\n", False) == BlockFmt.NONE
|
||||||
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
assert processStyle("##! Prologue\n", False) == BlockFmt.NONE
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user