V0.6 #852
|
@ -17,20 +17,19 @@ class SafeHTMLParser(HTMLParser):
|
||||||
'small', 'sound', 'source', 'spacer', 'span', 'strike', 'strong',
|
'small', 'sound', 'source', 'spacer', 'span', 'strike', 'strong',
|
||||||
'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'time', 'tfoot',
|
'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'time', 'tfoot',
|
||||||
'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'video']
|
'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'video']
|
||||||
replaces = [["&", "&"], ["\"", """], ["<", "<"], [">", ">"], ["\n", "<br/>"]]
|
replaces = [["&", "&"], ["\"", """], ["<", "<"], [">", ">"], ["\n", "<br/>"], ["\t", " "], [" ", " "], [" ", " "], ["<br/> ", "<br/> "]]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def multi_replace(text):
|
def multi_replace(text):
|
||||||
for a in SafeHTMLParser.replaces:
|
for a in SafeHTMLParser.replaces:
|
||||||
text = text.replace(a[0], a[1])
|
text = text.replace(a[0], a[1])
|
||||||
|
if len(text) > 1 and text[0] == " ":
|
||||||
|
text = " " + text[1:]
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
HTMLParser.__init__(self, *args, **kwargs)
|
HTMLParser.__init__(self, *args, **kwargs)
|
||||||
self.elements = set()
|
self.reset_safe()
|
||||||
self.sanitised = u""
|
|
||||||
self.raw = u""
|
|
||||||
self.has_html = False
|
|
||||||
|
|
||||||
def reset_safe(self):
|
def reset_safe(self):
|
||||||
self.elements = set()
|
self.elements = set()
|
||||||
|
|
Reference in New Issue
Block a user