Fix greater/lesser symbol bug in HTML conversion (#928)
* Fix issue with greater or lesser symbol in paragraph with formatting * Add test coverage and make another fix to special case of mixing formats
This commit is contained in:
committed by
GitHub
parent
32d6583ae3
commit
67d2e266fd
@@ -146,10 +146,25 @@ class ToHtml(Tokenizer):
|
||||
parStyle = None
|
||||
tmpResult = []
|
||||
|
||||
for tType, tLine, tText, tFormat, tStyle in self.theTokens:
|
||||
for tType, tLine, tDirty, tFormat, tStyle in self.theTokens:
|
||||
|
||||
# Replace < and > before adding html tags
|
||||
tText = tText.replace("<", "<").replace(">", ">")
|
||||
# Replace < and > and recompute formatting positions
|
||||
cText = []
|
||||
i = 0
|
||||
for c in tDirty:
|
||||
if c == "<":
|
||||
cText.append("<")
|
||||
tFormat = [[a + 3 if a > i else a, b, c] for a, b, c in tFormat]
|
||||
i += 4
|
||||
elif c == ">":
|
||||
cText.append(">")
|
||||
tFormat = [[a + 3 if a > i else a, b, c] for a, b, c in tFormat]
|
||||
i += 4
|
||||
else:
|
||||
cText.append(c)
|
||||
i += 1
|
||||
|
||||
tText = "".join(cText)
|
||||
|
||||
# Styles
|
||||
aStyle = []
|
||||
|
||||
@@ -378,6 +378,48 @@ def testCoreToHtml_ConvertDirect(mockGUI):
|
||||
# END Test testCoreToHtml_ConvertDirect
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreToHtml_SpecialCases(mockGUI):
|
||||
"""Test some special cases that has caused errors in the past.
|
||||
"""
|
||||
theProject = NWProject(mockGUI)
|
||||
theHtml = ToHtml(theProject)
|
||||
theHtml.isNovel = True
|
||||
|
||||
# Greater/Lesser than symbols
|
||||
# ===========================
|
||||
|
||||
theHtml.theText = "Text with > and < with some **bold text** in it.\n"
|
||||
theHtml.tokenizeText()
|
||||
theHtml.doConvert()
|
||||
assert theHtml.theResult == (
|
||||
"<p>Text with > and < with some <strong>bold text</strong> in it.</p>\n"
|
||||
)
|
||||
|
||||
theHtml.theText = "Text with some <**bold text**> in it.\n"
|
||||
theHtml.tokenizeText()
|
||||
theHtml.doConvert()
|
||||
assert theHtml.theResult == (
|
||||
"<p>Text with some <<strong>bold text</strong>> in it.</p>\n"
|
||||
)
|
||||
|
||||
theHtml.theText = "Let's > be > _difficult **shall** > we_?\n"
|
||||
theHtml.tokenizeText()
|
||||
theHtml.doConvert()
|
||||
assert theHtml.theResult == (
|
||||
"<p>Let's > be > <em>difficult <strong>shall</strong> > we</em>?</p>\n"
|
||||
)
|
||||
|
||||
theHtml.theText = "Test > text _<**bold**>_ and more.\n"
|
||||
theHtml.tokenizeText()
|
||||
theHtml.doConvert()
|
||||
assert theHtml.theResult == (
|
||||
"<p>Test > text <em><<strong>bold</strong>></em> and more.</p>\n"
|
||||
)
|
||||
|
||||
# END Test testCoreToHtml_SpecialCases
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreToHtml_Complex(mockGUI, fncDir):
|
||||
"""Test the save method of the ToHtml class.
|
||||
|
||||
Reference in New Issue
Block a user