X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fparse_html.py;h=1125dcc7170378d4b83f316e14a29465bb6451ed;hb=7d1dbd530c688dc71f98139efaf6890c84b12f94;hp=9f924c49597a3f4436fd477363ee7cd1fe1b5c32;hpb=48a7d1e88eebc93541bfaeb76a872d411c5e918e;p=bookmarks_db.git diff --git a/Robots/parse_html.py b/Robots/parse_html.py index 9f924c4..1125dcc 100755 --- a/Robots/parse_html.py +++ b/Robots/parse_html.py @@ -24,19 +24,29 @@ parsers.append(parse_html) import re -entity_re = re.compile("(&#[0-9]+;)") +from htmlentitydefs import entitydefs + +entity_re = re.compile("(&\w+;)") +num_entity_re = re.compile("(&#[0-9]+;)") def recode_entities(title, charset): output = [] - for part in entity_re.split(title): - if entity_re.match(part): + + for part in num_entity_re.split(title): + if num_entity_re.match(part): try: part = unichr(int(part[2:-1])).encode(charset) except UnicodeEncodeError: pass # Leave the entity as is output.append(part) - return ''.join(output) + output2 = [] + for part in entity_re.split(''.join(output)): + if entity_re.match(part): + part = entitydefs.get(part[1:-1], part) + output2.append(part) + + return ''.join(output2) def parse_html(filename, charset=None, log=None):