Merge 2.7.2 into main
This commit is contained in:
@@ -222,12 +222,24 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
"</p>\n"
|
||||
)
|
||||
|
||||
# Keywords
|
||||
|
||||
@pytest.mark.core
|
||||
def testFmtToHtml_ConvertMeta(mockGUI):
|
||||
"""Test meta data formats in the ToHtml class."""
|
||||
project = NWProject()
|
||||
html = ToHtml(project)
|
||||
html.initDocument()
|
||||
html._isNovel = True
|
||||
html._isFirst = True
|
||||
|
||||
# Keywords Disabled
|
||||
html.setKeywords(False)
|
||||
html._text = "@char: Bod, Jane\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html._pages[-1] == ""
|
||||
|
||||
# Keywords Enabled
|
||||
html.setKeywords(True)
|
||||
html._text = "@char: Bod, Jane\n"
|
||||
html.tokenizeText()
|
||||
@@ -239,7 +251,8 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
"<span style='color: #4271ae'><a href='#tag_jane'>Jane</a></span></p>\n"
|
||||
)
|
||||
|
||||
# Tags
|
||||
# Tags w/Colour
|
||||
html.setStyles(True)
|
||||
html._text = "@tag: Bod\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
@@ -257,7 +270,25 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
"<span style='color: #4271ae'>Nobody Owens</span></p>\n"
|
||||
)
|
||||
|
||||
# Multiple Keywords
|
||||
# Tags wo/Colour
|
||||
html.setStyles(False)
|
||||
html._text = "@tag: Bod\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html._pages[-1] == (
|
||||
"<p class='meta meta-tag'><strong>Tag:</strong> <a name='tag_bod'>Bod</a></p>\n"
|
||||
)
|
||||
|
||||
html._text = "@tag: Bod | Nobody Owens\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html._pages[-1] == (
|
||||
"<p class='meta meta-tag'><strong>Tag:</strong> "
|
||||
"<a name='tag_bod'>Bod</a> | Nobody Owens</p>\n"
|
||||
)
|
||||
|
||||
# Multiple Keywords w/Colour
|
||||
html.setStyles(True)
|
||||
html._isFirst = False
|
||||
html.setKeywords(True)
|
||||
html._text = "## Chapter\n\n@pov: Bod\n@plot: Main\n@location: Europe\n\n"
|
||||
@@ -276,6 +307,23 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
"<span style='color: #4271ae'><a href='#tag_europe'>Europe</a></span></p>\n"
|
||||
)
|
||||
|
||||
# Multiple Keywords wo/Colour
|
||||
html.setStyles(False)
|
||||
html._isFirst = False
|
||||
html.setKeywords(True)
|
||||
html._text = "## Chapter\n\n@pov: Bod\n@plot: Main\n@location: Europe\n\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html._pages[-1] == (
|
||||
"<h1 style='page-break-before: always;'>Chapter</h1>\n"
|
||||
"<p class='meta meta-pov' style='margin-bottom: 0;'>"
|
||||
"<strong>Point of View:</strong> <a href='#tag_bod'>Bod</a></p>\n"
|
||||
"<p class='meta meta-plot' style='margin-bottom: 0; margin-top: 0;'>"
|
||||
"<strong>Plot:</strong> <a href='#tag_main'>Main</a></p>\n"
|
||||
"<p class='meta meta-location' style='margin-top: 0;'>"
|
||||
"<strong>Locations:</strong> <a href='#tag_europe'>Europe</a></p>\n"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testFmtToHtml_Alignment(mockGUI):
|
||||
@@ -485,17 +533,6 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
# =========
|
||||
|
||||
html.setLinkHeadings(False)
|
||||
|
||||
# Align Left
|
||||
html.setStyles(False)
|
||||
html._blocks = [
|
||||
(BlockTyp.PART, tMeta, "A Title", [], BlockFmt.LEFT),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html._pages[-1] == (
|
||||
"<h1 class='title'>A Title</h1>\n"
|
||||
)
|
||||
|
||||
html.setStyles(True)
|
||||
|
||||
# Align Left
|
||||
@@ -709,33 +746,57 @@ def testFmtToHtml_Save(mockGUI, fncPath):
|
||||
|
||||
# Check Files
|
||||
# ===========
|
||||
|
||||
# HTML
|
||||
hStyle = html.getStyleSheet()
|
||||
htmlDoc = (
|
||||
|
||||
# HTML w/Styles
|
||||
html.setStyles(True)
|
||||
htmlDocCSS = (
|
||||
"<!DOCTYPE html>\n"
|
||||
"<html>\n"
|
||||
"<head>\n"
|
||||
"<meta charset='utf-8'>\n"
|
||||
"<title></title>\n"
|
||||
"<meta charset='utf-8'>\n"
|
||||
"<meta name='viewport' content='width=device-width, initial-scale=1'>\n"
|
||||
"<style>\n"
|
||||
"{htmlStyle:s}\n"
|
||||
"{style}\n"
|
||||
"</style>\n"
|
||||
"</head>\n"
|
||||
"<body>\n"
|
||||
"{bodyText:s}\n"
|
||||
"{body}\n"
|
||||
"</body>\n"
|
||||
"</html>\n"
|
||||
).format(
|
||||
htmlStyle="\n".join(hStyle),
|
||||
bodyText="".join(resText).rstrip()
|
||||
style="\n".join(hStyle),
|
||||
body="".join(resText).rstrip()
|
||||
)
|
||||
|
||||
saveFile = fncPath / "outFile.htm"
|
||||
html.saveDocument(saveFile)
|
||||
assert saveFile.read_text(encoding="utf-8") == htmlDoc
|
||||
assert saveFile.read_text(encoding="utf-8") == htmlDocCSS
|
||||
|
||||
# JSON + HTML
|
||||
# HTML wo/Styles
|
||||
html.setStyles(False)
|
||||
htmlDocCSS = (
|
||||
"<!DOCTYPE html>\n"
|
||||
"<html>\n"
|
||||
"<head>\n"
|
||||
"<title></title>\n"
|
||||
"<meta charset='utf-8'>\n"
|
||||
"</head>\n"
|
||||
"<body>\n"
|
||||
"{body}\n"
|
||||
"</body>\n"
|
||||
"</html>\n"
|
||||
).format(
|
||||
body="".join(resText).rstrip()
|
||||
)
|
||||
|
||||
saveFile = fncPath / "outFile.htm"
|
||||
html.saveDocument(saveFile)
|
||||
assert saveFile.read_text(encoding="utf-8") == htmlDocCSS
|
||||
|
||||
# JSON + HTML w/Styles
|
||||
html.setStyles(True)
|
||||
saveFile = fncPath / "outFile.json"
|
||||
html.saveDocument(saveFile)
|
||||
data = json.loads(saveFile.read_text(encoding="utf-8"))
|
||||
|
||||
@@ -783,7 +783,7 @@ def testFmtToken_MetaFormat(mockGUI):
|
||||
tokens._text = "% synopsis: The synopsis\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == [(
|
||||
BlockTyp.COMMENT, "", "Synopsis: The synopsis", [
|
||||
BlockTyp.SUMMARY, "", "Synopsis: The synopsis", [
|
||||
(0, TextFmt.B_B, ""), (0, TextFmt.COL_B, "modifier"),
|
||||
(9, TextFmt.COL_E, ""), (9, TextFmt.B_E, ""),
|
||||
(10, TextFmt.COL_B, "note"), (22, TextFmt.COL_E, "")
|
||||
@@ -800,13 +800,52 @@ def testFmtToken_MetaFormat(mockGUI):
|
||||
tokens._text = "% short: A short description\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == [(
|
||||
BlockTyp.COMMENT, "", "Short Description: A short description", [
|
||||
BlockTyp.SUMMARY, "", "Short Description: A short description", [
|
||||
(0, TextFmt.B_B, ""), (0, TextFmt.COL_B, "modifier"),
|
||||
(18, TextFmt.COL_E, ""), (18, TextFmt.B_E, ""),
|
||||
(19, TextFmt.COL_B, "note"), (38, TextFmt.COL_E, ""),
|
||||
], BlockFmt.NONE
|
||||
)]
|
||||
|
||||
# Story Comments
|
||||
tokens.setCommentType(nwComment.STORY, False)
|
||||
tokens.setCommentType(nwComment.NOTE, False)
|
||||
tokens._text = (
|
||||
"%Story.Stuff: Stuff happens\n"
|
||||
"%Note.More: That stuff that happened\n"
|
||||
"%Note.Other: That other stuff that happened\n"
|
||||
)
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == []
|
||||
|
||||
tokens.setCommentType(nwComment.STORY, True)
|
||||
tokens.setCommentType(nwComment.NOTE, True)
|
||||
tokens._text = (
|
||||
"%Story.Stuff: Stuff happens\n"
|
||||
"%Note.More: That stuff that happened\n"
|
||||
"%Note.Other: That other stuff that happened\n"
|
||||
)
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == [(
|
||||
BlockTyp.NOTE, "", "Story Structure (Stuff): Stuff happens", [
|
||||
(0, TextFmt.B_B, ""), (0, TextFmt.COL_B, "modifier"),
|
||||
(24, TextFmt.COL_E, ""), (24, TextFmt.B_E, ""),
|
||||
(25, TextFmt.COL_B, "note"), (38, TextFmt.COL_E, "")
|
||||
], BlockFmt.Z_BTM
|
||||
), (
|
||||
BlockTyp.NOTE, "", "Note (More): That stuff that happened", [
|
||||
(0, TextFmt.B_B, ""), (0, TextFmt.COL_B, "modifier"),
|
||||
(12, TextFmt.COL_E, ""), (12, TextFmt.B_E, ""),
|
||||
(13, TextFmt.COL_B, "note"), (37, TextFmt.COL_E, "")
|
||||
], BlockFmt.Z_TOP | BlockFmt.Z_BTM
|
||||
), (
|
||||
BlockTyp.NOTE, "", "Note (Other): That other stuff that happened", [
|
||||
(0, TextFmt.B_B, ""), (0, TextFmt.COL_B, "modifier"),
|
||||
(13, TextFmt.COL_E, ""), (13, TextFmt.B_E, ""),
|
||||
(14, TextFmt.COL_B, "note"), (44, TextFmt.COL_E, "")
|
||||
], BlockFmt.Z_TOP
|
||||
)]
|
||||
|
||||
# Keyword
|
||||
tokens.setKeywords(False)
|
||||
tokens._text = "@char: Bod\n"
|
||||
@@ -919,6 +958,11 @@ def testFmtToken_ExtractFormats(mockGUI):
|
||||
assert text == "Text with strikethrough in it."
|
||||
assert fmt == [(10, TextFmt.D_B, ""), (23, TextFmt.D_E, "")]
|
||||
|
||||
# Plain mark
|
||||
text, fmt = tokens._extractFormats("Text with ==a highlight== in it.")
|
||||
assert text == "Text with a highlight in it."
|
||||
assert fmt == [(10, TextFmt.M_B, ""), (21, TextFmt.M_E, "")]
|
||||
|
||||
# Nested bold/italics
|
||||
text, fmt = tokens._extractFormats("Text with **bold and _italics_** in it.")
|
||||
assert text == "Text with bold and italics in it."
|
||||
@@ -1632,7 +1676,7 @@ def testFmtToken_TextIndent(mockGUI):
|
||||
]
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.HEAD3, TM1, "Scene Two", [], BlockFmt.NONE),
|
||||
(BlockTyp.COMMENT, "", "Synopsis: Stuff happens.", tFmt, BlockFmt.NONE),
|
||||
(BlockTyp.SUMMARY, "", "Synopsis: Stuff happens.", tFmt, BlockFmt.NONE),
|
||||
]
|
||||
assert tokens._noIndent is True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user