Combine the different ways of storing generated text data in formats
This commit is contained in:
@@ -47,7 +47,7 @@ def testFmtToHtml_ConvertHeaders(mockGUI):
|
||||
html._text = "# Partition\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 class='title' style='text-align: center;'>Partition</h1>\n"
|
||||
)
|
||||
|
||||
@@ -55,7 +55,7 @@ def testFmtToHtml_ConvertHeaders(mockGUI):
|
||||
html._text = "## Chapter Title\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 style='page-break-before: always;'>Chapter Title</h1>\n"
|
||||
)
|
||||
|
||||
@@ -63,19 +63,19 @@ def testFmtToHtml_ConvertHeaders(mockGUI):
|
||||
html._text = "### Scene Title\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == "<h2>Scene Title</h2>\n"
|
||||
assert html._pages[-1] == "<h2>Scene Title</h2>\n"
|
||||
|
||||
# Header 4
|
||||
html._text = "#### Section Title\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == "<h3>Section Title</h3>\n"
|
||||
assert html._pages[-1] == "<h3>Section Title</h3>\n"
|
||||
|
||||
# Title
|
||||
html._text = "#! Title\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 class='title' style='text-align: center; page-break-before: always;'>Title</h1>\n"
|
||||
)
|
||||
|
||||
@@ -83,7 +83,7 @@ def testFmtToHtml_ConvertHeaders(mockGUI):
|
||||
html._text = "##! Prologue\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == "<h1 style='page-break-before: always;'>Prologue</h1>\n"
|
||||
assert html._pages[-1] == "<h1 style='page-break-before: always;'>Prologue</h1>\n"
|
||||
|
||||
# Note Files Headers
|
||||
# ==================
|
||||
@@ -97,31 +97,31 @@ def testFmtToHtml_ConvertHeaders(mockGUI):
|
||||
html._text = "# Heading One\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == "<h1><a name='0000000000000:T0001'></a>Heading One</h1>\n"
|
||||
assert html._pages[-1] == "<h1><a name='0000000000000:T0001'></a>Heading One</h1>\n"
|
||||
|
||||
# Header 2
|
||||
html._text = "## Heading Two\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == "<h2><a name='0000000000000:T0001'></a>Heading Two</h2>\n"
|
||||
assert html._pages[-1] == "<h2><a name='0000000000000:T0001'></a>Heading Two</h2>\n"
|
||||
|
||||
# Header 3
|
||||
html._text = "### Heading Three\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == "<h3><a name='0000000000000:T0001'></a>Heading Three</h3>\n"
|
||||
assert html._pages[-1] == "<h3><a name='0000000000000:T0001'></a>Heading Three</h3>\n"
|
||||
|
||||
# Header 4
|
||||
html._text = "#### Heading Four\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == "<h4><a name='0000000000000:T0001'></a>Heading Four</h4>\n"
|
||||
assert html._pages[-1] == "<h4><a name='0000000000000:T0001'></a>Heading Four</h4>\n"
|
||||
|
||||
# Title
|
||||
html._text = "#! Heading One\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 class='title' style='text-align: center; page-break-before: always;'>"
|
||||
"<a name='0000000000000:T0001'></a>Heading One</h1>\n"
|
||||
)
|
||||
@@ -130,7 +130,7 @@ def testFmtToHtml_ConvertHeaders(mockGUI):
|
||||
html._text = "##! Heading Two\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == "<h2><a name='0000000000000:T0001'></a>Heading Two</h2>\n"
|
||||
assert html._pages[-1] == "<h2><a name='0000000000000:T0001'></a>Heading Two</h2>\n"
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
@@ -150,7 +150,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Some <strong>nested bold and <em>italic</em> and "
|
||||
"<del>strikethrough</del> text</strong> here</p>\n"
|
||||
)
|
||||
@@ -162,7 +162,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
)
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Some <strong>bold</strong>, <em>italic</em>, <del>strike</del>, "
|
||||
"<span style='text-decoration: underline;'>underline</span>, <mark>mark</mark>, "
|
||||
"super<sup>script</sup>, sub<sub>script</sub> here</p>\n"
|
||||
@@ -172,7 +172,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html._text = "Line one\nLine two\nLine three\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Line one<br>Line two<br>Line three</p>\n"
|
||||
)
|
||||
|
||||
@@ -180,13 +180,13 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html._text = "%synopsis: The synopsis ...\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == ""
|
||||
assert html._pages[-1] == ""
|
||||
|
||||
html.setSynopsis(True)
|
||||
html._text = "%synopsis: The synopsis ...\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p class='comment'>"
|
||||
"<strong><span style='color: #813709'>Synopsis:</span></strong> "
|
||||
"<span style='color: #813709'>The synopsis ...</span>"
|
||||
@@ -197,7 +197,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html._text = "%short: A short description ...\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p class='comment'>"
|
||||
"<strong><span style='color: #813709'>Short Description:</span></strong> "
|
||||
"<span style='color: #813709'>A short description ...</span>"
|
||||
@@ -208,13 +208,13 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html._text = "% A comment ...\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == ""
|
||||
assert html._pages[-1] == ""
|
||||
|
||||
html.setComments(True)
|
||||
html._text = "% A comment ...\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p class='comment'>"
|
||||
"<strong><span style='color: #646464'>Comment:</span></strong> "
|
||||
"<span style='color: #646464'>A comment ...</span>"
|
||||
@@ -225,13 +225,13 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html._text = "@char: Bod, Jane\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == ""
|
||||
assert html._pages[-1] == ""
|
||||
|
||||
html.setKeywords(True)
|
||||
html._text = "@char: Bod, Jane\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p class='meta meta-char'><strong><span style='color: #f5871f'>"
|
||||
"Characters:</span></strong> "
|
||||
"<span style='color: #4271ae'><a href='#tag_bod'>Bod</a></span>, "
|
||||
@@ -242,7 +242,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html._text = "@tag: Bod\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p class='meta meta-tag'><strong><span style='color: #f5871f'>Tag:</span></strong> "
|
||||
"<span style='color: #4271ae'><a name='tag_bod'>Bod</a></span></p>\n"
|
||||
)
|
||||
@@ -250,7 +250,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html._text = "@tag: Bod | Nobody Owens\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p class='meta meta-tag'><strong><span style='color: #f5871f'>Tag:</span></strong> "
|
||||
"<span style='color: #4271ae'><a name='tag_bod'>Bod</a></span> | "
|
||||
"<span style='color: #4271ae'>Nobody Owens</span></p>\n"
|
||||
@@ -262,7 +262,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html._text = "## Chapter\n\n@pov: Bod\n@plot: Main\n@location: Europe\n\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 style='page-break-before: always;'>Chapter</h1>\n"
|
||||
"<p class='meta meta-pov' style='margin-bottom: 0;'>"
|
||||
"<strong><span style='color: #f5871f'>Point of View:</span></strong> "
|
||||
@@ -280,7 +280,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html._text = "## Chapter\n\nThis text \u201chas dialogue\u201d in it.\n\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 style='page-break-before: always;'>Chapter</h1>\n"
|
||||
"<p>This text <span style='color: #4271ae'>“has dialogue”</span> in it.</p>\n"
|
||||
)
|
||||
@@ -292,7 +292,7 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
html._text = "## Chapter\n\nThis text ::has alt dialogue:: in it.\n\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 style='page-break-before: always;'>Chapter</h1>\n"
|
||||
"<p>This text <span style='color: #813709'>::has alt dialogue::</span> in it.</p>\n"
|
||||
)
|
||||
@@ -306,15 +306,17 @@ def testFmtToHtml_ConvertParagraphs(mockGUI):
|
||||
)
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Text with one<sup><a href='#footnote_1'>1</a></sup> "
|
||||
"or two<sup>ERR</sup> footnotes.</p>\n"
|
||||
)
|
||||
|
||||
html.appendFootnotes()
|
||||
assert html.result == (
|
||||
assert html._pages[-2] == (
|
||||
"<p>Text with one<sup><a href='#footnote_1'>1</a></sup> "
|
||||
"or two<sup>ERR</sup> footnotes.</p>\n"
|
||||
)
|
||||
assert html._pages[-1] == (
|
||||
"<h3>Footnotes</h3>\n"
|
||||
"<ol>\n"
|
||||
"<li id='footnote_1'><p>Footnote text A.</p></li>\n"
|
||||
@@ -336,7 +338,7 @@ def testFmtToHtml_CloseTags(mockGUI):
|
||||
html._text = "Text [b][i][s][u][m][sup][sub]text text text.\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Text <strong><em><del><span style='text-decoration: underline;'><mark><sup><sub>"
|
||||
"text text text.</strong></em></del></span></mark></sup></sub></p>\n"
|
||||
)
|
||||
@@ -345,7 +347,7 @@ def testFmtToHtml_CloseTags(mockGUI):
|
||||
html._text = "Text [b][i][s][u][m][sup][sub]text [b][i][s][u][m][sup][sub]text text.\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Text <strong><em><del><span style='text-decoration: underline;'><mark><sup><sub>"
|
||||
"text text text.</strong></em></del></span></mark></sup></sub></p>\n"
|
||||
)
|
||||
@@ -354,7 +356,7 @@ def testFmtToHtml_CloseTags(mockGUI):
|
||||
html._text = "Text text [/b][/i][/s][/u][/m][/sup][/sub]text text.\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Text text text text.</p>\n"
|
||||
)
|
||||
|
||||
@@ -380,7 +382,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.TITLE, tMeta, "A Title", [], BlockFmt.PBB | BlockFmt.CENTRE),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 class='title' style='text-align: center; page-break-before: always;'>"
|
||||
"<a name='0000000000000:T0001'></a>A Title</h1>\n"
|
||||
)
|
||||
@@ -390,7 +392,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.HEAD2, tMeta, "Prologue", [], BlockFmt.PBB),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 style='page-break-before: always;'>"
|
||||
"<a name='0000000000000:T0001'></a>Prologue</h1>\n"
|
||||
)
|
||||
@@ -403,14 +405,14 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.SEP, tMeta, "* * *", [], BlockFmt.CENTRE),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == "<p class='sep' style='text-align: center;'>* * *</p>\n"
|
||||
assert html._pages[-1] == "<p class='sep' style='text-align: center;'>* * *</p>\n"
|
||||
|
||||
# Skip
|
||||
html._blocks = [
|
||||
(BlockTyp.SKIP, tMeta, "", [], BlockFmt.NONE),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == "<p> </p>\n"
|
||||
assert html._pages[-1] == "<p> </p>\n"
|
||||
|
||||
# Alignment
|
||||
# =========
|
||||
@@ -423,7 +425,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.LEFT),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 class='title'>A Title</h1>\n"
|
||||
)
|
||||
|
||||
@@ -434,7 +436,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.LEFT),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 class='title' style='text-align: left;'>A Title</h1>\n"
|
||||
)
|
||||
|
||||
@@ -443,7 +445,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.RIGHT),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 class='title' style='text-align: right;'>A Title</h1>\n"
|
||||
)
|
||||
|
||||
@@ -452,7 +454,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.CENTRE),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 class='title' style='text-align: center;'>A Title</h1>\n"
|
||||
)
|
||||
|
||||
@@ -461,7 +463,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.JUSTIFY),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 class='title' style='text-align: justify;'>A Title</h1>\n"
|
||||
)
|
||||
|
||||
@@ -473,7 +475,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.HEAD1, tMeta, "A Title", [], BlockFmt.PBB | BlockFmt.PBA),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 class='title' "
|
||||
"style='page-break-before: always; page-break-after: always;'>A Title</h1>\n"
|
||||
)
|
||||
@@ -486,7 +488,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.TEXT, tMeta, "Some text ...", [], BlockFmt.IND_L),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p style='margin-left: 4.00em;'>Some text ...</p>\n"
|
||||
)
|
||||
|
||||
@@ -495,7 +497,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.TEXT, tMeta, "Some text ...", [], BlockFmt.IND_R),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p style='margin-right: 4.00em;'>Some text ...</p>\n"
|
||||
)
|
||||
|
||||
@@ -504,7 +506,7 @@ def testFmtToHtml_ConvertDirect(mockGUI):
|
||||
(BlockTyp.TEXT, tMeta, "Some text ...", [], BlockFmt.IND_T),
|
||||
]
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p style='text-indent: 1.40em;'>Some text ...</p>\n"
|
||||
)
|
||||
|
||||
@@ -523,28 +525,28 @@ def testFmtToHtml_SpecialCases(mockGUI):
|
||||
html._text = "Text with > and < with some **bold text** in it.\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Text with > and < with some <strong>bold text</strong> in it.</p>\n"
|
||||
)
|
||||
|
||||
html._text = "Text with some <**bold text**> in it.\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Text with some <<strong>bold text</strong>> in it.</p>\n"
|
||||
)
|
||||
|
||||
html._text = "Let's > be > _difficult **shall** > we_?\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Let's > be > <em>difficult <strong>shall</strong> > we</em>?</p>\n"
|
||||
)
|
||||
|
||||
html._text = "Test > text _<**bold**>_ and more.\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Test > text <em><<strong>bold</strong>></em> and more.</p>\n"
|
||||
)
|
||||
|
||||
@@ -556,7 +558,7 @@ def testFmtToHtml_SpecialCases(mockGUI):
|
||||
html._text = "% Test > text _<**bold**>_ and more.\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p class='comment'>"
|
||||
"<strong><span style='color: #646464'>Comment:</span></strong> "
|
||||
"<span style='color: #646464'>Test > text <em><<strong>bold</strong>></em> "
|
||||
@@ -568,7 +570,7 @@ def testFmtToHtml_SpecialCases(mockGUI):
|
||||
html._text = "## Heading <1>\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<h1 style='page-break-before: always;'>Heading <1></h1>\n"
|
||||
)
|
||||
|
||||
@@ -579,7 +581,7 @@ def testFmtToHtml_SpecialCases(mockGUI):
|
||||
html._text = "Test text \\**_bold_** and more.\n"
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Test text **<em>bold</em>** and more.</p>\n"
|
||||
)
|
||||
|
||||
@@ -632,9 +634,8 @@ def testFmtToHtml_Save(mockGUI, fncPath):
|
||||
html.doPreProcessing()
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == resText[i]
|
||||
|
||||
assert html.fullHTML == resText
|
||||
assert html._pages == resText
|
||||
|
||||
html.replaceTabs(nSpaces=2, spaceChar=" ")
|
||||
resText[6] = "<h3>A Section</h3>\n<p> More text in scene two.</p>\n"
|
||||
@@ -695,7 +696,7 @@ def testFmtToHtml_Methods(mockGUI):
|
||||
html.doPreProcessing()
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Text with <brackets> & short–dash, long—dash …</p>\n"
|
||||
)
|
||||
|
||||
@@ -706,7 +707,7 @@ def testFmtToHtml_Methods(mockGUI):
|
||||
html.doPreProcessing()
|
||||
html.tokenizeText()
|
||||
html.doConvert()
|
||||
assert html.result == (
|
||||
assert html._pages[-1] == (
|
||||
"<p>Text with <brackets> & short–dash, long—dash …</p>\n"
|
||||
)
|
||||
|
||||
|
||||
@@ -157,8 +157,6 @@ def testFmtToken_Setters(mockGUI):
|
||||
assert tokens._doKeywords is True
|
||||
|
||||
# Properties
|
||||
assert tokens.result == ""
|
||||
assert tokens.allMarkdown == []
|
||||
assert tokens.textStats == {}
|
||||
assert tokens.errData == []
|
||||
|
||||
@@ -211,14 +209,14 @@ def testFmtToken_TextOps(monkeypatch, mockGUI, mockRnd, fncPath):
|
||||
|
||||
# First Page
|
||||
tokens.addRootHeading(C.hPlotRoot)
|
||||
assert tokens.allMarkdown[-1] == "#! Notes: Plot\n\n"
|
||||
assert tokens._raw[-1] == "#! Notes: Plot\n\n"
|
||||
assert tokens._blocks[-1] == (
|
||||
BlockTyp.TITLE, "0000000000009:T0001", "Notes: Plot", [], BlockFmt.CENTRE
|
||||
)
|
||||
|
||||
# Not First Page
|
||||
tokens.addRootHeading(C.hPlotRoot)
|
||||
assert tokens.allMarkdown[-1] == "#! Notes: Plot\n\n"
|
||||
assert tokens._raw[-1] == "#! Notes: Plot\n\n"
|
||||
assert tokens._blocks[-1] == (
|
||||
BlockTyp.TITLE, "0000000000009:T0001", "Notes: Plot", [], BlockFmt.CENTRE | BlockFmt.PBB
|
||||
)
|
||||
@@ -283,7 +281,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.TITLE, TM1, "Novel Title", [], BlockFmt.CENTRE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "#! Novel Title\n\n"
|
||||
assert tokens._raw[-1] == "#! Novel Title\n\n"
|
||||
|
||||
# Note File
|
||||
tokens._isNovel = False
|
||||
@@ -294,7 +292,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.TITLE, TM1, "Note Title", [], BlockFmt.CENTRE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "#! Note Title\n\n"
|
||||
assert tokens._raw[-1] == "#! Note Title\n\n"
|
||||
|
||||
# Header 1
|
||||
# ========
|
||||
@@ -308,7 +306,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.HEAD1, TM1, "Novel Title", [], BlockFmt.CENTRE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "# Novel Title\n\n"
|
||||
assert tokens._raw[-1] == "# Novel Title\n\n"
|
||||
|
||||
# Note File
|
||||
tokens._isNovel = False
|
||||
@@ -319,7 +317,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.HEAD1, TM1, "Note Title", [], BlockFmt.NONE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "# Note Title\n\n"
|
||||
assert tokens._raw[-1] == "# Note Title\n\n"
|
||||
|
||||
# Header 2
|
||||
# ========
|
||||
@@ -332,7 +330,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.HEAD2, TM1, "Chapter One", [], BlockFmt.PBB),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "## Chapter One\n\n"
|
||||
assert tokens._raw[-1] == "## Chapter One\n\n"
|
||||
|
||||
# Note File
|
||||
tokens._isNovel = False
|
||||
@@ -342,7 +340,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.HEAD2, TM1, "Heading 2", [], BlockFmt.NONE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "## Heading 2\n\n"
|
||||
assert tokens._raw[-1] == "## Heading 2\n\n"
|
||||
|
||||
# Header 3
|
||||
# ========
|
||||
@@ -355,7 +353,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.HEAD3, TM1, "Scene One", [], BlockFmt.NONE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "### Scene One\n\n"
|
||||
assert tokens._raw[-1] == "### Scene One\n\n"
|
||||
|
||||
# Note File
|
||||
tokens._isNovel = False
|
||||
@@ -365,7 +363,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.HEAD3, TM1, "Heading 3", [], BlockFmt.NONE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "### Heading 3\n\n"
|
||||
assert tokens._raw[-1] == "### Heading 3\n\n"
|
||||
|
||||
# Header 4
|
||||
# ========
|
||||
@@ -378,7 +376,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.HEAD4, TM1, "A Section", [], BlockFmt.NONE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "#### A Section\n\n"
|
||||
assert tokens._raw[-1] == "#### A Section\n\n"
|
||||
|
||||
# Note File
|
||||
tokens._isNovel = False
|
||||
@@ -388,7 +386,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.HEAD4, TM1, "Heading 4", [], BlockFmt.NONE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "#### Heading 4\n\n"
|
||||
assert tokens._raw[-1] == "#### Heading 4\n\n"
|
||||
|
||||
# Title
|
||||
# =====
|
||||
@@ -402,7 +400,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.TITLE, TM1, "Title", [], BlockFmt.PBB | BlockFmt.CENTRE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "#! Title\n\n"
|
||||
assert tokens._raw[-1] == "#! Title\n\n"
|
||||
|
||||
# Note File
|
||||
tokens._isNovel = False
|
||||
@@ -413,7 +411,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.TITLE, TM1, "Title", [], BlockFmt.PBB | BlockFmt.CENTRE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "#! Title\n\n"
|
||||
assert tokens._raw[-1] == "#! Title\n\n"
|
||||
|
||||
# Unnumbered
|
||||
# ==========
|
||||
@@ -426,7 +424,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.HEAD2, TM1, "Prologue", [], BlockFmt.PBB),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "##! Prologue\n\n"
|
||||
assert tokens._raw[-1] == "##! Prologue\n\n"
|
||||
|
||||
# Note File
|
||||
tokens._isNovel = False
|
||||
@@ -436,7 +434,7 @@ def testFmtToken_HeaderFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.HEAD2, TM1, "Prologue", [], BlockFmt.NONE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "##! Prologue\n\n"
|
||||
assert tokens._raw[-1] == "##! Prologue\n\n"
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
@@ -711,14 +709,14 @@ def testFmtToken_MetaFormat(mockGUI):
|
||||
tokens._text = "%~ Some text\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == []
|
||||
assert tokens.allMarkdown[-1] == "\n"
|
||||
assert tokens._raw[-1] == "\n"
|
||||
|
||||
# Comment
|
||||
tokens.setComments(False)
|
||||
tokens._text = "% A comment\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == []
|
||||
assert tokens.allMarkdown[-1] == "\n"
|
||||
assert tokens._raw[-1] == "\n"
|
||||
|
||||
tokens.setComments(True)
|
||||
tokens._text = "% A comment\n"
|
||||
@@ -730,14 +728,14 @@ def testFmtToken_MetaFormat(mockGUI):
|
||||
(9, TextFmt.COL_B, "comment"), (18, TextFmt.COL_E, ""),
|
||||
], BlockFmt.NONE
|
||||
)]
|
||||
assert tokens.allMarkdown[-1] == "% A comment\n\n"
|
||||
assert tokens._raw[-1] == "% A comment\n\n"
|
||||
|
||||
# Synopsis
|
||||
tokens.setSynopsis(False)
|
||||
tokens._text = "%synopsis: The synopsis\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == []
|
||||
assert tokens.allMarkdown[-1] == "\n"
|
||||
assert tokens._raw[-1] == "\n"
|
||||
|
||||
tokens.setSynopsis(True)
|
||||
tokens._text = "% synopsis: The synopsis\n"
|
||||
@@ -749,14 +747,14 @@ def testFmtToken_MetaFormat(mockGUI):
|
||||
(10, TextFmt.COL_B, "synopsis"), (22, TextFmt.COL_E, "")
|
||||
], BlockFmt.NONE
|
||||
)]
|
||||
assert tokens.allMarkdown[-1] == "% synopsis: The synopsis\n\n"
|
||||
assert tokens._raw[-1] == "% synopsis: The synopsis\n\n"
|
||||
|
||||
# Short
|
||||
tokens.setSynopsis(False)
|
||||
tokens._text = "% short: A short description\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == []
|
||||
assert tokens.allMarkdown[-1] == "\n"
|
||||
assert tokens._raw[-1] == "\n"
|
||||
|
||||
tokens.setSynopsis(True)
|
||||
tokens._text = "% short: A short description\n"
|
||||
@@ -768,14 +766,14 @@ def testFmtToken_MetaFormat(mockGUI):
|
||||
(19, TextFmt.COL_B, "synopsis"), (38, TextFmt.COL_E, ""),
|
||||
], BlockFmt.NONE
|
||||
)]
|
||||
assert tokens.allMarkdown[-1] == "% short: A short description\n\n"
|
||||
assert tokens._raw[-1] == "% short: A short description\n\n"
|
||||
|
||||
# Keyword
|
||||
tokens.setKeywords(False)
|
||||
tokens._text = "@char: Bod\n"
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == []
|
||||
assert tokens.allMarkdown[-1] == "\n"
|
||||
assert tokens._raw[-1] == "\n"
|
||||
|
||||
tokens.setKeywords(True)
|
||||
tokens.tokenizeText()
|
||||
@@ -787,7 +785,7 @@ def testFmtToken_MetaFormat(mockGUI):
|
||||
(15, TextFmt.HRF_E, ""), (15, TextFmt.COL_E, ""),
|
||||
], BlockFmt.NONE
|
||||
)]
|
||||
assert tokens.allMarkdown[-1] == "@char: Bod\n\n"
|
||||
assert tokens._raw[-1] == "@char: Bod\n\n"
|
||||
|
||||
tokens._text = "@pov: Bod\n@plot: Main\n@location: Europe\n"
|
||||
tokens.tokenizeText()
|
||||
@@ -813,7 +811,7 @@ def testFmtToken_MetaFormat(mockGUI):
|
||||
(17, TextFmt.HRF_E, ""), (17, TextFmt.COL_E, ""),
|
||||
], BlockFmt.Z_TOP
|
||||
)]
|
||||
assert tokens.allMarkdown[-1] == "@pov: Bod\n@plot: Main\n@location: Europe\n\n"
|
||||
assert tokens._raw[-1] == "@pov: Bod\n@plot: Main\n@location: Europe\n\n"
|
||||
|
||||
# Ignored keywords
|
||||
tokens._text = "@pov: Bod\n@plot: Main\n@location: Europe\n"
|
||||
@@ -859,7 +857,7 @@ def testFmtToken_MarginFormat(mockGUI):
|
||||
(BlockTyp.TEXT, "", "Double-indented block", [], dblIndent),
|
||||
(BlockTyp.TEXT, "", "Right-indent, right-aligned", [], rIndAlign),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == (
|
||||
assert tokens._raw[-1] == (
|
||||
"Some regular text\n\n"
|
||||
"Some left-aligned text\n\n"
|
||||
"Some right-aligned text\n\n"
|
||||
@@ -1063,12 +1061,12 @@ def testFmtToken_TextFormat(mockGUI):
|
||||
assert tokens._blocks == [
|
||||
(BlockTyp.TEXT, "", "Some plain text\non two lines", [], BlockFmt.NONE),
|
||||
]
|
||||
assert tokens.allMarkdown[-1] == "Some plain text\non two lines\n\n\n\n"
|
||||
assert tokens._raw[-1] == "Some plain text\non two lines\n\n\n\n"
|
||||
|
||||
tokens.setBodyText(False)
|
||||
tokens.tokenizeText()
|
||||
assert tokens._blocks == []
|
||||
assert tokens.allMarkdown[-1] == "\n\n\n"
|
||||
assert tokens._raw[-1] == "\n\n\n"
|
||||
tokens.setBodyText(True)
|
||||
|
||||
# Text Emphasis
|
||||
@@ -1082,7 +1080,7 @@ def testFmtToken_TextFormat(mockGUI):
|
||||
],
|
||||
BlockFmt.NONE
|
||||
)]
|
||||
assert tokens.allMarkdown[-1] == "Some **bolded text** on this lines\n\n"
|
||||
assert tokens._raw[-1] == "Some **bolded text** on this lines\n\n"
|
||||
|
||||
tokens._text = "Some _italic text_ on this lines\n"
|
||||
tokens.tokenizeText()
|
||||
@@ -1094,7 +1092,7 @@ def testFmtToken_TextFormat(mockGUI):
|
||||
],
|
||||
BlockFmt.NONE
|
||||
)]
|
||||
assert tokens.allMarkdown[-1] == "Some _italic text_ on this lines\n\n"
|
||||
assert tokens._raw[-1] == "Some _italic text_ on this lines\n\n"
|
||||
|
||||
tokens._text = "Some **_bold italic text_** on this lines\n"
|
||||
tokens.tokenizeText()
|
||||
@@ -1108,7 +1106,7 @@ def testFmtToken_TextFormat(mockGUI):
|
||||
],
|
||||
BlockFmt.NONE
|
||||
)]
|
||||
assert tokens.allMarkdown[-1] == "Some **_bold italic text_** on this lines\n\n"
|
||||
assert tokens._raw[-1] == "Some **_bold italic text_** on this lines\n\n"
|
||||
|
||||
tokens._text = "Some ~~strikethrough text~~ on this lines\n"
|
||||
tokens.tokenizeText()
|
||||
@@ -1120,7 +1118,7 @@ def testFmtToken_TextFormat(mockGUI):
|
||||
],
|
||||
BlockFmt.NONE
|
||||
)]
|
||||
assert tokens.allMarkdown[-1] == "Some ~~strikethrough text~~ on this lines\n\n"
|
||||
assert tokens._raw[-1] == "Some ~~strikethrough text~~ on this lines\n\n"
|
||||
|
||||
tokens._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
|
||||
tokens.tokenizeText()
|
||||
@@ -1136,7 +1134,7 @@ def testFmtToken_TextFormat(mockGUI):
|
||||
],
|
||||
BlockFmt.NONE
|
||||
)]
|
||||
assert tokens.allMarkdown[-1] == (
|
||||
assert tokens._raw[-1] == (
|
||||
"Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n\n"
|
||||
)
|
||||
|
||||
@@ -2032,7 +2030,7 @@ def testFmtToken_SceneSeparators(mockGUI):
|
||||
md.setHardSceneFormat("* * *", False)
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md.result == (
|
||||
assert md._pages[-1] == (
|
||||
"# T: Title One\n\n"
|
||||
"Text\n\n"
|
||||
"~\n\n"
|
||||
@@ -2048,7 +2046,7 @@ def testFmtToken_SceneSeparators(mockGUI):
|
||||
md.setHardSceneFormat(f"H: {nwHeadFmt.TITLE}", False)
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md.result == (
|
||||
assert md._pages[-1] == (
|
||||
"# T: Title One\n\n"
|
||||
"### S: Scene One\n\n"
|
||||
"Text\n\n"
|
||||
@@ -2086,7 +2084,7 @@ def testFmtToken_SceneSeparators(mockGUI):
|
||||
md.setHardSceneFormat("* * *", False)
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md.result == (
|
||||
assert md._pages[-1] == (
|
||||
"# T: Title One\n\n"
|
||||
"## C: Chapter One\n\n"
|
||||
"Text\n\n"
|
||||
@@ -2103,7 +2101,7 @@ def testFmtToken_SceneSeparators(mockGUI):
|
||||
md.setHardSceneFormat(f"H: {nwHeadFmt.TITLE}", False)
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md.result == (
|
||||
assert md._pages[-1] == (
|
||||
"# T: Title One\n\n"
|
||||
"## C: Chapter One\n\n"
|
||||
"### S: Scene One\n\n"
|
||||
@@ -2138,7 +2136,7 @@ def testFmtToken_SceneSeparators(mockGUI):
|
||||
md.setHardSceneFormat("* * *", False)
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md.result == (
|
||||
assert md._pages[-1] == (
|
||||
"Text\n\n"
|
||||
"\u205f\n\n"
|
||||
"Text\n\n"
|
||||
@@ -2190,7 +2188,7 @@ def testFmtToken_HeaderVisibility(mockGUI):
|
||||
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md.result == (
|
||||
assert md._pages[-1] == (
|
||||
"# Novel\n\n"
|
||||
"# Title One\n\n"
|
||||
"## Prologue\n\n"
|
||||
@@ -2218,7 +2216,7 @@ def testFmtToken_HeaderVisibility(mockGUI):
|
||||
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md.result == (
|
||||
assert md._pages[-1] == (
|
||||
"# Novel\n\n"
|
||||
"Text\n\n"
|
||||
"Text\n\n"
|
||||
@@ -2242,7 +2240,7 @@ def testFmtToken_HeaderVisibility(mockGUI):
|
||||
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md.result == (
|
||||
assert md._pages[-1] == (
|
||||
"# Novel\n\n"
|
||||
"# Title One\n\n"
|
||||
"## Prologue\n\n"
|
||||
@@ -2316,7 +2314,7 @@ def testFmtToken_CounterHandling(mockGUI):
|
||||
# Two Novel Format
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md.result == (
|
||||
assert md._pages[-1] == (
|
||||
"# Novel One\n\n"
|
||||
"## U: Prologue\n\n"
|
||||
"Text\n\n"
|
||||
|
||||
@@ -31,161 +31,161 @@ from novelwriter.formats.tomarkdown import ToMarkdown
|
||||
def testFmtToMarkdown_ConvertHeaders(mockGUI):
|
||||
"""Test header formats in the ToMarkdown class."""
|
||||
project = NWProject()
|
||||
toMD = ToMarkdown(project, False)
|
||||
md = ToMarkdown(project, False)
|
||||
|
||||
toMD._isNovel = True
|
||||
toMD._isFirst = True
|
||||
md._isNovel = True
|
||||
md._isFirst = True
|
||||
|
||||
# Header 1
|
||||
toMD._text = "# Partition\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "# Partition\n\n"
|
||||
md._text = "# Partition\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "# Partition\n\n"
|
||||
|
||||
# Header 2
|
||||
toMD._text = "## Chapter Title\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "## Chapter Title\n\n"
|
||||
md._text = "## Chapter Title\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "## Chapter Title\n\n"
|
||||
|
||||
# Header 3
|
||||
toMD._text = "### Scene Title\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "### Scene Title\n\n"
|
||||
md._text = "### Scene Title\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "### Scene Title\n\n"
|
||||
|
||||
# Header 4
|
||||
toMD._text = "#### Section Title\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "#### Section Title\n\n"
|
||||
md._text = "#### Section Title\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "#### Section Title\n\n"
|
||||
|
||||
# Title
|
||||
toMD._text = "#! Title\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "# Title\n\n"
|
||||
md._text = "#! Title\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "# Title\n\n"
|
||||
|
||||
# Unnumbered
|
||||
toMD._text = "##! Prologue\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "## Prologue\n\n"
|
||||
md._text = "##! Prologue\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "## Prologue\n\n"
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testFmtToMarkdown_ConvertParagraphs(mockGUI):
|
||||
"""Test paragraph formats in the ToMarkdown class."""
|
||||
project = NWProject()
|
||||
toMD = ToMarkdown(project, False)
|
||||
md = ToMarkdown(project, False)
|
||||
|
||||
toMD._isNovel = True
|
||||
toMD._isFirst = True
|
||||
md._isNovel = True
|
||||
md._isFirst = True
|
||||
|
||||
# Text for Extended Markdown
|
||||
toMD._extended = True
|
||||
toMD._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == (
|
||||
md._extended = True
|
||||
md._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == (
|
||||
"Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n\n"
|
||||
)
|
||||
|
||||
# Text for Standard Markdown
|
||||
toMD._extended = False
|
||||
toMD._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == (
|
||||
md._extended = False
|
||||
md._text = "Some **nested bold and _italic_ and ~~strikethrough~~ text** here\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == (
|
||||
"Some **nested bold and _italic_ and strikethrough text** here\n\n"
|
||||
)
|
||||
|
||||
# Shortcodes for Extended Markdown
|
||||
toMD._extended = True
|
||||
toMD._text = (
|
||||
md._extended = True
|
||||
md._text = (
|
||||
"Some [b]bold[/b], [i]italic[/i], [s]strike[/s], [u]underline[/u], [m]mark[/m], "
|
||||
"super[sup]script[/sup], sub[sub]script[/sub] here\n"
|
||||
)
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == (
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == (
|
||||
"Some **bold**, _italic_, ~~strike~~, underline, ==mark==, "
|
||||
"super^script^, sub~script~ here\n\n"
|
||||
)
|
||||
|
||||
# Shortcodes for Standard Markdown
|
||||
toMD._extended = False
|
||||
toMD._text = (
|
||||
md._extended = False
|
||||
md._text = (
|
||||
"Some [b]bold[/b], [i]italic[/i], [s]strike[/s], [u]underline[/u], [m]mark[/m], "
|
||||
"super[sup]script[/sup], sub[sub]script[/sub] here\n"
|
||||
)
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == (
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == (
|
||||
"Some **bold**, _italic_, strike, underline, mark, superscript, subscript here\n\n"
|
||||
)
|
||||
|
||||
# Text w/Hard Break
|
||||
toMD._text = "Line one\nLine two\nLine three\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "Line one \nLine two \nLine three\n\n"
|
||||
md._text = "Line one\nLine two\nLine three\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "Line one \nLine two \nLine three\n\n"
|
||||
|
||||
# Text wo/Hard Break
|
||||
toMD._text = "Line one\nLine two\nLine three\n"
|
||||
toMD.setKeepLineBreaks(False)
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "Line one Line two Line three\n\n"
|
||||
md._text = "Line one\nLine two\nLine three\n"
|
||||
md.setKeepLineBreaks(False)
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "Line one Line two Line three\n\n"
|
||||
|
||||
# Synopsis, Short
|
||||
toMD._text = "%synopsis: The synopsis ...\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == ""
|
||||
md._text = "%synopsis: The synopsis ...\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == ""
|
||||
|
||||
toMD.setSynopsis(True)
|
||||
toMD._text = "%synopsis: The synopsis ...\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "**Synopsis:** The synopsis ...\n\n"
|
||||
md.setSynopsis(True)
|
||||
md._text = "%synopsis: The synopsis ...\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "**Synopsis:** The synopsis ...\n\n"
|
||||
|
||||
toMD.setSynopsis(True)
|
||||
toMD._text = "%short: A description ...\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "**Short Description:** A description ...\n\n"
|
||||
md.setSynopsis(True)
|
||||
md._text = "%short: A description ...\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "**Short Description:** A description ...\n\n"
|
||||
|
||||
# Comment
|
||||
toMD._text = "% A comment ...\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == ""
|
||||
md._text = "% A comment ...\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == ""
|
||||
|
||||
toMD.setComments(True)
|
||||
toMD._text = "% A comment ...\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "**Comment:** A comment ...\n\n"
|
||||
md.setComments(True)
|
||||
md._text = "% A comment ...\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "**Comment:** A comment ...\n\n"
|
||||
|
||||
# Keywords
|
||||
toMD._text = "@char: Bod, Jane\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == ""
|
||||
md._text = "@char: Bod, Jane\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == ""
|
||||
|
||||
toMD.setKeywords(True)
|
||||
toMD._text = "@char: Bod, Jane\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "**Characters:** Bod, Jane\n\n"
|
||||
md.setKeywords(True)
|
||||
md._text = "@char: Bod, Jane\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "**Characters:** Bod, Jane\n\n"
|
||||
|
||||
# Multiple Keywords
|
||||
toMD.setKeywords(True)
|
||||
toMD._text = "## Chapter\n\n@pov: Bod\n@plot: Main\n@location: Europe\n\n"
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == (
|
||||
md.setKeywords(True)
|
||||
md._text = "## Chapter\n\n@pov: Bod\n@plot: Main\n@location: Europe\n\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == (
|
||||
"## Chapter\n\n"
|
||||
"**Point of View:** Bod \n"
|
||||
"**Plot:** Main \n"
|
||||
@@ -193,17 +193,19 @@ def testFmtToMarkdown_ConvertParagraphs(mockGUI):
|
||||
)
|
||||
|
||||
# Footnotes
|
||||
toMD._text = (
|
||||
md._text = (
|
||||
"Text with one[footnote:fa] or two[footnote:fb] footnotes.\n\n"
|
||||
"%footnote.fa: Footnote text A.\n\n"
|
||||
)
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "Text with one[1] or two[ERR] footnotes.\n\n"
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "Text with one[1] or two[ERR] footnotes.\n\n"
|
||||
|
||||
toMD.appendFootnotes()
|
||||
assert toMD.result == (
|
||||
md.appendFootnotes()
|
||||
assert md._pages[-2] == (
|
||||
"Text with one[1] or two[ERR] footnotes.\n\n"
|
||||
)
|
||||
assert md._pages[-1] == (
|
||||
"### Footnotes\n\n"
|
||||
"1. Footnote text A.\n\n"
|
||||
)
|
||||
@@ -213,43 +215,43 @@ def testFmtToMarkdown_ConvertParagraphs(mockGUI):
|
||||
def testFmtToMarkdown_ConvertDirect(mockGUI):
|
||||
"""Test the converter directly using the ToMarkdown class."""
|
||||
project = NWProject()
|
||||
toMD = ToMarkdown(project, False)
|
||||
toMD._isNovel = True
|
||||
md = ToMarkdown(project, False)
|
||||
md._isNovel = True
|
||||
|
||||
# Special Titles
|
||||
# ==============
|
||||
|
||||
# Title
|
||||
toMD._blocks = [
|
||||
md._blocks = [
|
||||
(BlockTyp.TITLE, "", "A Title", [], BlockFmt.PBB | BlockFmt.CENTRE),
|
||||
]
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "# A Title\n\n"
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "# A Title\n\n"
|
||||
|
||||
# Separators
|
||||
# ==========
|
||||
|
||||
# Separator
|
||||
toMD._blocks = [
|
||||
md._blocks = [
|
||||
(BlockTyp.SEP, "", "* * *", [], BlockFmt.CENTRE),
|
||||
]
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "* * *\n\n"
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "* * *\n\n"
|
||||
|
||||
# Skip
|
||||
toMD._blocks = [
|
||||
md._blocks = [
|
||||
(BlockTyp.SKIP, "", "", [], BlockFmt.NONE),
|
||||
]
|
||||
toMD.doConvert()
|
||||
assert toMD.result == "\n\n"
|
||||
md.doConvert()
|
||||
assert md._pages[-1] == "\n\n"
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testFmtToMarkdown_Save(mockGUI, fncPath):
|
||||
"""Test the save method of the ToMarkdown class."""
|
||||
project = NWProject()
|
||||
toMD = ToMarkdown(project, False)
|
||||
toMD._isNovel = True
|
||||
md = ToMarkdown(project, False)
|
||||
md._isNovel = True
|
||||
|
||||
# Build Project
|
||||
# =============
|
||||
@@ -274,22 +276,21 @@ def testFmtToMarkdown_Save(mockGUI, fncPath):
|
||||
]
|
||||
|
||||
for i in range(len(docText)):
|
||||
toMD._text = docText[i]
|
||||
toMD.doPreProcessing()
|
||||
toMD.tokenizeText()
|
||||
toMD.doConvert()
|
||||
assert toMD.result == resText[i]
|
||||
md._text = docText[i]
|
||||
md.doPreProcessing()
|
||||
md.tokenizeText()
|
||||
md.doConvert()
|
||||
|
||||
assert toMD.fullMD == resText
|
||||
assert toMD.getFullResultSize() == len("".join(resText))
|
||||
assert md._pages == resText
|
||||
assert md.getFullResultSize() == len("".join(resText))
|
||||
|
||||
toMD.replaceTabs(nSpaces=4, spaceChar=" ")
|
||||
md.replaceTabs(nSpaces=4, spaceChar=" ")
|
||||
resText[6] = "#### A Section\n\n More text in scene two.\n\n"
|
||||
assert toMD.fullMD == resText
|
||||
assert md._pages == resText
|
||||
|
||||
# Check File
|
||||
# ==========
|
||||
|
||||
saveFile = fncPath / "outFile.md"
|
||||
toMD.saveDocument(saveFile)
|
||||
md.saveDocument(saveFile)
|
||||
assert saveFile.read_text(encoding="utf-8") == "".join(resText)
|
||||
|
||||
Reference in New Issue
Block a user