From 4087a7004f1d98600d4b3a453513852f55bc93fe Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 10 Dec 2013 10:27:33 +0530 Subject: [PATCH] Fix usage of entitiy definitions from html5lib --- src/calibre/__init__.py | 4 ++-- src/calibre/ebooks/html_entities.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/calibre/ebooks/html_entities.py diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index fdfb91d7bb..917df54f6b 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -562,9 +562,9 @@ def entity_to_unicode(match, exceptions=[], encoding='cp1252', return check(chr(num).decode(encoding)) except UnicodeDecodeError: return check(my_unichr(num)) - from html5lib.constants import entities + from calibre.ebooks.html_entities import html5_entities try: - return check(entities[ent]) + return check(html5_entities[ent]) except KeyError: pass from htmlentitydefs import name2codepoint diff --git a/src/calibre/ebooks/html_entities.py b/src/calibre/ebooks/html_entities.py new file mode 100644 index 0000000000..aba8ba80e1 --- /dev/null +++ b/src/calibre/ebooks/html_entities.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8 +from __future__ import (unicode_literals, division, absolute_import, + print_function) + +__license__ = 'GPL v3' +__copyright__ = '2013, Kovid Goyal ' + +from html5lib.constants import entities + +html5_entities = {k.replace(';', ''):v for k, v in entities.iteritems()} +