Resolve HTML render bug (#951)

* Fix bug breaking HTML rendering with angle brackets in other blocks than normal text
* Restore cursor if document viewer fails to load
* Improve test coverage
This commit is contained in:
Veronica Berglyd Olsen
2022-01-04 20:52:36 +01:00
committed by GitHub
parent 59e10fbf0a
commit 9be2519406
4 changed files with 67 additions and 31 deletions
+23 -17
View File
@@ -154,25 +154,31 @@ class ToHtml(Tokenizer):
parStyle = None
tmpResult = []
for tType, tLine, tDirty, tFormat, tStyle in self._theTokens:
for tType, tLine, tText, tFormat, tStyle in self._theTokens:
# Replace < and > and recompute formatting positions
cText = []
i = 0
for c in tDirty:
if c == "<":
cText.append("&lt;")
tFormat = [[a + 3 if a > i else a, b, c] for a, b, c in tFormat]
i += 4
elif c == ">":
cText.append("&gt;")
tFormat = [[a + 3 if a > i else a, b, c] for a, b, c in tFormat]
i += 4
else:
cText.append(c)
i += 1
# Replace < and > with HTML entities
if tFormat:
# If we have formatting, we must recompute the locations
cText = []
i = 0
for c in tText:
if c == "<":
cText.append("&lt;")
tFormat = [[a + 3 if a > i else a, b, c] for a, b, c in tFormat]
i += 4
elif c == ">":
cText.append("&gt;")
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)
tText = "".join(cText)
else:
# If we don't have formatting, we can do a plain replace
tText = tText.replace("<", "&lt;").replace(">", "&gt;")
# Styles
aStyle = []