Tokenize dialogue with colour tag

This commit is contained in:
Veronica Berglyd Olsen
2024-10-22 18:41:34 +02:00
parent c537d0f396
commit 63f9cd0bac
13 changed files with 107 additions and 146 deletions
+25 -6
View File
@@ -35,6 +35,7 @@ def testFmtToHtml_ConvertHeaders(mockGUI):
"""Test header formats in the ToHtml class."""
project = NWProject()
html = ToHtml(project)
html.initDocument()
# Novel Files Headers
# ===================
@@ -137,6 +138,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
"""Test paragraph formats in the ToHtml class."""
project = NWProject()
html = ToHtml(project)
html.initDocument()
html._isNovel = True
html._isFirst = True
@@ -185,7 +187,10 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
html.tokenizeText()
html.doConvert()
assert html.result == (
"<p class='synopsis'><strong>Synopsis:</strong> The synopsis ...</p>\n"
"<p class='comment'>"
"<strong><span style='color: #813709'>Synopsis:</strong></span> "
"<span style='color: #813709'>The synopsis ...</span>"
"</p>\n"
)
html.setSynopsis(True)
@@ -193,7 +198,10 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
html.tokenizeText()
html.doConvert()
assert html.result == (
"<p class='synopsis'><strong>Short Description:</strong> A short description ...</p>\n"
"<p class='comment'>"
"<strong><span style='color: #813709'>Short Description:</strong></span> "
"<span style='color: #813709'>A short description ...</span>"
"</p>\n"
)
# Comment
@@ -207,7 +215,10 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
html.tokenizeText()
html.doConvert()
assert html.result == (
"<p class='comment'><strong>Comment:</strong> A comment ...</p>\n"
"<p class='comment'>"
"<strong><span style='color: #646464'>Comment:</strong></span> "
"<span style='color: #646464'>A comment ...</span>"
"</p>\n"
)
# Keywords
@@ -269,7 +280,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
html.doConvert()
assert html.result == (
"<h1 style='page-break-before: always;'>Chapter</h1>\n"
"<p>This text <span class='dialog'>\u201chas dialogue\u201d</span> in it.</p>\n"
"<p>This text <span style='color: #4271ae'>“has dialogue</span> in it.</p>\n"
)
# Alt. Dialogue
@@ -281,7 +292,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
html.doConvert()
assert html.result == (
"<h1 style='page-break-before: always;'>Chapter</h1>\n"
"<p>This text <span class='altdialog'>::has alt dialogue::</span> in it.</p>\n"
"<p>This text <span style='color: #813709'>::has alt dialogue::</span> in it.</p>\n"
)
# Footnotes
@@ -314,6 +325,7 @@ def testFmtToHtml_CloseTags(mockGUI):
"""Test automatic closing of HTML tags for shortcodes."""
project = NWProject()
html = ToHtml(project)
html.initDocument()
html._isNovel = True
html._isFirst = True
@@ -350,6 +362,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
"""Test the converter directly using the ToHtml class."""
project = NWProject()
html = ToHtml(project)
html.initDocument()
html._isNovel = True
html._handle = "0000000000000"
@@ -497,6 +510,7 @@ def testFmtToHtml_SpecialCases(mockGUI):
"""Test some special cases that have caused errors in the past."""
project = NWProject()
html = ToHtml(project)
html.initDocument()
html._isNovel = True
# Greater/Lesser than symbols
@@ -540,7 +554,9 @@ def testFmtToHtml_SpecialCases(mockGUI):
html.doConvert()
assert html.result == (
"<p class='comment'>"
"<strong>Comment:</strong> Test &gt; text <em>&lt;<strong>bold</strong>&gt;</em> and more."
"<strong><span style='color: #646464'>Comment:</strong></span> "
"<span style='color: #646464'>Test &gt; text <em>&lt;<strong>bold</strong>&gt;</em> "
"and more.</span>"
"</p>\n"
)
@@ -569,6 +585,7 @@ def testFmtToHtml_Save(mockGUI, fncPath):
"""Test the save method of the ToHtml class."""
project = NWProject()
html = ToHtml(project)
html.initDocument()
html._isNovel = True
# Build Project
@@ -665,6 +682,7 @@ def testFmtToHtml_Methods(mockGUI):
"""Test all the other methods of the ToHtml class."""
project = NWProject()
html = ToHtml(project)
html.initDocument()
# Auto-Replace, keep Unicode
docText = "Text with <brackets> & shortdash, long—dash …\n"
@@ -707,6 +725,7 @@ def testFmtToHtml_Format(mockGUI):
"""Test all the formatters for the ToHtml class."""
project = NWProject()
html = ToHtml(project)
html.initDocument()
assert html._formatKeywords("") == ("", "")
assert html._formatKeywords("tag: Jane") == (
+22 -22
View File
@@ -736,7 +736,7 @@ def testFmtToken_MetaFormat(mockGUI):
tokens._text = "% synopsis: The synopsis\n"
tokens.tokenizeText()
assert tokens._blocks == [(
BlockTyp.SUMMARY, 0, "Synopsis: The synopsis", [
BlockTyp.COMMENT, 0, "Synopsis: The synopsis", [
(0, TextFmt.B_B, ""), (0, TextFmt.COL_B, "modifier"), (9, TextFmt.B_E, ""),
(9, TextFmt.COL_E, ""), (10, TextFmt.COL_B, "synopsis"), (22, TextFmt.COL_E, "")
], BlockFmt.NONE
@@ -754,7 +754,7 @@ def testFmtToken_MetaFormat(mockGUI):
tokens._text = "% short: A short description\n"
tokens.tokenizeText()
assert tokens._blocks == [(
BlockTyp.SUMMARY, 0, "Short Description: A short description", [
BlockTyp.COMMENT, 0, "Short Description: A short description", [
(0, TextFmt.B_B, ""), (0, TextFmt.COL_B, "modifier"), (18, TextFmt.B_E, ""),
(18, TextFmt.COL_E, ""), (19, TextFmt.COL_B, "synopsis"), (38, TextFmt.COL_E, ""),
], BlockFmt.NONE
@@ -1129,10 +1129,10 @@ def testFmtToken_Dialogue(mockGUI):
BlockTyp.TEXT, 0,
"Text with \u2018dialogue one,\u2019 and \u2018dialogue two.\u2019",
[
(10, TextFmt.DL_B, ""),
(25, TextFmt.DL_E, ""),
(30, TextFmt.DL_B, ""),
(45, TextFmt.DL_E, ""),
(10, TextFmt.COL_B, "dialog"),
(25, TextFmt.COL_E, ""),
(30, TextFmt.COL_B, "dialog"),
(45, TextFmt.COL_E, ""),
],
BlockFmt.NONE
)]
@@ -1144,10 +1144,10 @@ def testFmtToken_Dialogue(mockGUI):
BlockTyp.TEXT, 0,
"Text with \u201cdialogue one,\u201d and \u201cdialogue two.\u201d",
[
(10, TextFmt.DL_B, ""),
(25, TextFmt.DL_E, ""),
(30, TextFmt.DL_B, ""),
(45, TextFmt.DL_E, ""),
(10, TextFmt.COL_B, "dialog"),
(25, TextFmt.COL_E, ""),
(30, TextFmt.COL_B, "dialog"),
(45, TextFmt.COL_E, ""),
],
BlockFmt.NONE
)]
@@ -1159,10 +1159,10 @@ def testFmtToken_Dialogue(mockGUI):
BlockTyp.TEXT, 0,
"Text with ::dialogue one,:: and ::dialogue two.::",
[
(10, TextFmt.ADL_B, ""),
(27, TextFmt.ADL_E, ""),
(32, TextFmt.ADL_B, ""),
(49, TextFmt.ADL_E, ""),
(10, TextFmt.COL_B, "altdialog"),
(27, TextFmt.COL_E, ""),
(32, TextFmt.COL_B, "altdialog"),
(49, TextFmt.COL_E, ""),
],
BlockFmt.NONE
)]
@@ -1174,10 +1174,10 @@ def testFmtToken_Dialogue(mockGUI):
BlockTyp.TEXT, 0,
"\u2013 Dialogue with a narrator break, \u2013he said,\u2013 see?",
[
(0, TextFmt.DL_B, ""),
(34, TextFmt.DL_E, ""),
(44, TextFmt.DL_B, ""),
(49, TextFmt.DL_E, ""),
(0, TextFmt.COL_B, "dialog"),
(34, TextFmt.COL_E, ""),
(44, TextFmt.COL_B, "dialog"),
(49, TextFmt.COL_E, ""),
],
BlockFmt.NONE
)]
@@ -1193,9 +1193,9 @@ def testFmtToken_Dialogue(mockGUI):
"\u201cDialogue text.\u201d",
[
(0, TextFmt.I_B, ""),
(0, TextFmt.DL_B, ""),
(0, TextFmt.COL_B, "dialog"),
(16, TextFmt.I_E, ""),
(16, TextFmt.DL_E, ""),
(16, TextFmt.COL_E, ""),
],
BlockFmt.NONE
)]
@@ -1407,8 +1407,8 @@ def testFmtToken_TextIndent(mockGUI):
(9, TextFmt.COL_E, ""), (10, TextFmt.COL_B, "synopsis"), (24, TextFmt.COL_E, ""),
]
assert tokens._blocks == [
(BlockTyp.HEAD3, 1, "Scene Two", [], BlockFmt.NONE),
(BlockTyp.SUMMARY, 1, "Synopsis: Stuff happens.", tFmt, BlockFmt.NONE),
(BlockTyp.HEAD3, 1, "Scene Two", [], BlockFmt.NONE),
(BlockTyp.COMMENT, 1, "Synopsis: Stuff happens.", tFmt, BlockFmt.NONE),
]
assert tokens._noIndent is True
+2 -2
View File
@@ -248,7 +248,7 @@ def testFmtToOdt_DialogueFormatting(mockGUI):
# Regular dialogue
text = "Text with 'dialogue in it.'"
fmt = [(10, TextFmt.DL_B, ""), (27, TextFmt.DL_E, "")]
fmt = [(10, TextFmt.COL_B, "dialog"), (27, TextFmt.COL_E, "")]
xTest = ET.Element(_mkTag("office", "text"))
odt._addTextPar(xTest, "Standard", oStyle, text, tFmt=fmt)
assert odt.errData == []
@@ -261,7 +261,7 @@ def testFmtToOdt_DialogueFormatting(mockGUI):
# Alternative dialogue
text = "Text with ::dialogue in it.::"
fmt = [(10, TextFmt.ADL_B, ""), (29, TextFmt.ADL_E, "")]
fmt = [(10, TextFmt.COL_B, "altdialog"), (29, TextFmt.COL_E, "")]
xTest = ET.Element(_mkTag("office", "text"))
odt._addTextPar(xTest, "Standard", oStyle, text, tFmt=fmt)
assert odt.errData == []