mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #1275 (converting opf to epub)
This commit is contained in:
parent
a4efa9b305
commit
e6d872c317
@ -30,7 +30,7 @@ def detect(aBuf):
|
|||||||
|
|
||||||
# Added by Kovid
|
# Added by Kovid
|
||||||
ENCODING_PATS = [
|
ENCODING_PATS = [
|
||||||
re.compile(r'<[^<>]+encoding=[\'"](.*?)[\'"][^<>]*>', re.IGNORECASE),
|
re.compile(r'<\?[^<>]+encoding=[\'"](.*?)[\'"][^<>]*>', re.IGNORECASE),
|
||||||
re.compile(r'<meta.*?content=[\'"].*?charset=([^\s\'"]+).*?[\'"].*?>', re.IGNORECASE)
|
re.compile(r'<meta.*?content=[\'"].*?charset=([^\s\'"]+).*?[\'"].*?>', re.IGNORECASE)
|
||||||
]
|
]
|
||||||
ENTITY_PATTERN = re.compile(r'&(\S+?);')
|
ENTITY_PATTERN = re.compile(r'&(\S+?);')
|
||||||
|
@ -273,10 +273,11 @@ class Spine(ResourceCollection):
|
|||||||
for itemref in itemrefs:
|
for itemref in itemrefs:
|
||||||
idref = itemref.get('idref', None)
|
idref = itemref.get('idref', None)
|
||||||
if idref is not None:
|
if idref is not None:
|
||||||
r = Spine.Item(s.manifest.id_for_path,
|
path = s.manifest.path_for_id(idref)
|
||||||
s.manifest.path_for_id(idref), is_path=True)
|
if path:
|
||||||
r.is_linear = itemref.get('linear', 'yes') == 'yes'
|
r = Spine.Item(s.manifest.id_for_path, path, is_path=True)
|
||||||
s.append(r)
|
r.is_linear = itemref.get('linear', 'yes') == 'yes'
|
||||||
|
s.append(r)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -439,7 +440,7 @@ class OPF(object):
|
|||||||
stream = open(stream, 'rb')
|
stream = open(stream, 'rb')
|
||||||
self.basedir = self.base_dir = basedir
|
self.basedir = self.base_dir = basedir
|
||||||
raw, self.encoding = xml_to_unicode(stream.read(), strip_encoding_pats=True, resolve_entities=True)
|
raw, self.encoding = xml_to_unicode(stream.read(), strip_encoding_pats=True, resolve_entities=True)
|
||||||
|
raw = raw[raw.find('<'):]
|
||||||
self.root = etree.fromstring(raw, self.PARSER)
|
self.root = etree.fromstring(raw, self.PARSER)
|
||||||
self.metadata = self.metadata_path(self.root)
|
self.metadata = self.metadata_path(self.root)
|
||||||
if not self.metadata:
|
if not self.metadata:
|
||||||
@ -983,4 +984,4 @@ def main(args=sys.argv):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(test())
|
sys.exit(test())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user