mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Fix searching for text that is represented as entities in the underlying HTML. Fixes #899573 (Private bug)
This commit is contained in:
parent
e45cd49796
commit
2d5501cc9e
@ -18,7 +18,8 @@ from calibre.ebooks.chardet import xml_to_unicode
|
|||||||
from calibre.utils.zipfile import safe_replace
|
from calibre.utils.zipfile import safe_replace
|
||||||
from calibre.utils.config import DynamicConfig
|
from calibre.utils.config import DynamicConfig
|
||||||
from calibre.utils.logging import Log
|
from calibre.utils.logging import Log
|
||||||
from calibre import guess_type, prints, prepare_string_for_xml
|
from calibre import (guess_type, prints, prepare_string_for_xml,
|
||||||
|
xml_replace_entities)
|
||||||
from calibre.ebooks.oeb.transforms.cover import CoverManager
|
from calibre.ebooks.oeb.transforms.cover import CoverManager
|
||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
|
|
||||||
@ -96,13 +97,19 @@ class EbookIterator(object):
|
|||||||
self.ebook_ext = ext.replace('original_', '')
|
self.ebook_ext = ext.replace('original_', '')
|
||||||
|
|
||||||
def search(self, text, index, backwards=False):
|
def search(self, text, index, backwards=False):
|
||||||
text = text.lower()
|
text = prepare_string_for_xml(text.lower())
|
||||||
pmap = [(i, path) for i, path in enumerate(self.spine)]
|
pmap = [(i, path) for i, path in enumerate(self.spine)]
|
||||||
if backwards:
|
if backwards:
|
||||||
pmap.reverse()
|
pmap.reverse()
|
||||||
for i, path in pmap:
|
for i, path in pmap:
|
||||||
if (backwards and i < index) or (not backwards and i > index):
|
if (backwards and i < index) or (not backwards and i > index):
|
||||||
if text in open(path, 'rb').read().decode(path.encoding).lower():
|
with open(path, 'rb') as f:
|
||||||
|
raw = f.read().decode(path.encoding)
|
||||||
|
try:
|
||||||
|
raw = xml_replace_entities(raw)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
if text in raw.lower():
|
||||||
return i
|
return i
|
||||||
|
|
||||||
def find_missing_css_files(self):
|
def find_missing_css_files(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user