Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,16 @@ def func(match):
except Exception:
return match.group(0)
return entity.sub(func, text)


def replace_entities3(text):
entity = re.compile(r'&#x([abcdefABCDEF0-9]{2});')
def func(match):
try:
return unichr(int('0x'+match.group(1),0))
except Exception:
return match.group(0)
return entity.sub(func, text)

def remove_markup(text):
html = re.compile(r'<[^>]+>')
return html.sub(' ', text)
Expand All @@ -250,8 +259,10 @@ def format(text, max_length=400):
previous = ''
while text != previous:
previous = text
text = text.replace('&amp;', '&')
text = replace_entities1(text)
text = replace_entities2(text)
text = replace_entities3(text)
text = remove_markup(text)
text = ' '.join(text.split())
if len(text) > max_length:
Expand Down