Make the LIT-encased OEB1 books a bit more compliant.

This commit is contained in:
Marshall T. Vandegrift 2008-12-11 08:00:51 -05:00
parent 8f1e5cad88
commit 96dbea5394
2 changed files with 10 additions and 5 deletions

View File

@ -499,7 +499,7 @@ class Oeb(object):
for element in opf.xpath('metadata/x-metadata/meta'): for element in opf.xpath('metadata/x-metadata/meta'):
metadata.append(element) metadata.append(element)
for item in opf.xpath('manifest/item'): for item in opf.xpath('manifest/item'):
media_type = item.attrib['media-type'] media_type = item.attrib['media-type'].lower()
if media_type in OEB_DOCS: if media_type in OEB_DOCS:
media_type = XHTML_MIME media_type = XHTML_MIME
elif media_type in OEB_STYLES: elif media_type in OEB_STYLES:

View File

@ -15,8 +15,8 @@ from urllib import unquote as urlunquote
from lxml import etree from lxml import etree
from calibre.ebooks.lit.reader import msguid, DirectoryEntry from calibre.ebooks.lit.reader import msguid, DirectoryEntry
import calibre.ebooks.lit.maps as maps import calibre.ebooks.lit.maps as maps
from calibre.ebooks.lit.oeb import OEB_STYLES, OEB_CSS_MIME, CSS_MIME, \ from calibre.ebooks.lit.oeb import OEB_CSS_MIME, CSS_MIME, XHTML_MIME, \
OPF_MIME, XML_NS, XML OPF_MIME, OEB_STYLES, OEB_DOCS, XML_NS, XML
from calibre.ebooks.lit.oeb import namespace, barename, urlnormalize from calibre.ebooks.lit.oeb import namespace, barename, urlnormalize
from calibre.ebooks.lit.oeb import Oeb from calibre.ebooks.lit.oeb import Oeb
from calibre.ebooks.lit.stylizer import Stylizer from calibre.ebooks.lit.stylizer import Stylizer
@ -28,6 +28,9 @@ import calibre.ebooks.lit.mssha1 as mssha1
__all__ = ['LitWriter'] __all__ = ['LitWriter']
LIT_IMAGES = set(['image/png', 'image/jpeg', 'image/gif'])
LIT_MIMES = OEB_DOCS | OEB_STYLES | LIT_IMAGES
def invert_tag_map(tag_map): def invert_tag_map(tag_map):
tags, dattrs, tattrs = tag_map tags, dattrs, tattrs = tag_map
tags = dict((tags[i], i) for i in xrange(len(tags))) tags = dict((tags[i], i) for i in xrange(len(tags)))
@ -195,7 +198,7 @@ class ReBinary(object):
self.anchors.append((value, tag_offset)) self.anchors.append((value, tag_offset))
elif attr.startswith('ms--'): elif attr.startswith('ms--'):
attr = '%' + attr[4:] attr = '%' + attr[4:]
elif attr == 'type' and value in OEB_STYLES: elif tag == 'link' and attr == 'type' and value in OEB_STYLES:
value = OEB_CSS_MIME value = OEB_CSS_MIME
if attr in tattrs: if attr in tattrs:
self.write(tattrs[attr]) self.write(tattrs[attr])
@ -411,6 +414,8 @@ class LitWriter(object):
def _build_data(self): def _build_data(self):
self._add_folder('/data') self._add_folder('/data')
for item in self._oeb.manifest.values(): for item in self._oeb.manifest.values():
if item.media_type not in LIT_MIMES:
continue
name = '/data/' + item.id name = '/data/' + item.id
data = item.data data = item.data
secnum = 0 secnum = 0
@ -435,7 +440,7 @@ class LitWriter(object):
manifest[key].append(item) manifest[key].append(item)
elif item.media_type == CSS_MIME: elif item.media_type == CSS_MIME:
manifest['css'].append(item) manifest['css'].append(item)
else: elif item.media_type in LIT_IMAGES:
manifest['images'].append(item) manifest['images'].append(item)
data = StringIO() data = StringIO()
data.write(pack('<Bc', 1, '\\')) data.write(pack('<Bc', 1, '\\'))