Move the coding of angle brackets in HTML to the innermost function in the chain (#821)

This commit is contained in:
Veronica Berglyd Olsen
2021-07-04 18:05:26 +02:00
committed by GitHub
parent 72fd2990e7
commit 1d16cc2a03
4 changed files with 9 additions and 66 deletions
+7 -10
View File
@@ -74,19 +74,13 @@ class ToHtml(Tokenizer):
return
def setReplaceUnicode(self, doReplace):
"""Set the translation map to either minimal or full unicode to
"""Set the translation map to either minimal or full unicode for
html entities replacement.
"""
# Control characters must always be replaced
# This affects alignment and indenting code, so the Tokenizer
# must take this into account when parsing for markup using
# angle brackets.
self._trMap = str.maketrans({
"<": "&lt;",
">": "&gt;",
"&": "&amp;",
})
# Angle brackets are replaced later as they are also used in
# formatting codes
self._trMap = str.maketrans({"&": "&amp;"})
if doReplace:
# Extend to all relevant Unicode characters
self._trMap.update(str.maketrans(nwHtmlUnicode.U_TO_H))
@@ -157,6 +151,9 @@ class ToHtml(Tokenizer):
for tType, tLine, tText, tFormat, tStyle in self.theTokens:
# Replace < and > before adding html tags
tText = tText.replace("<", "&lt;").replace(">", "&gt;")
# Styles
aStyle = []
if tStyle is not None and self.cssStyles: