mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fixes for Mobipocket extraction:
- Fix #1817. Ignore invalid filepos hyperlink targets. - From output of book producing #1817 noticed bug with <i/> and </b> -> <span/> conversion. Move conversion to post-parsing. - Correct image MIME type in output OPF.
This commit is contained in:
parent
dcd258b52b
commit
2326873b7c
@ -247,9 +247,6 @@ class MobiReader(object):
|
|||||||
self.processed_html = '<html><p>'+self.processed_html.replace('\n\n', '<p>')+'</html>'
|
self.processed_html = '<html><p>'+self.processed_html.replace('\n\n', '<p>')+'</html>'
|
||||||
self.processed_html = self.processed_html.replace('\r\n', '\n')
|
self.processed_html = self.processed_html.replace('\r\n', '\n')
|
||||||
self.processed_html = self.processed_html.replace('> <', '>\n<')
|
self.processed_html = self.processed_html.replace('> <', '>\n<')
|
||||||
for t, c in [('b', 'bold'), ('i', 'italic')]:
|
|
||||||
self.processed_html = re.sub(r'(?i)<%s>'%t, r'<span class="%s">'%c, self.processed_html)
|
|
||||||
self.processed_html = re.sub(r'(?i)</%s>'%t, r'</span>', self.processed_html)
|
|
||||||
|
|
||||||
def upshift_markup(self, root):
|
def upshift_markup(self, root):
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
@ -295,27 +292,35 @@ class MobiReader(object):
|
|||||||
styles.append('page-break-before: always')
|
styles.append('page-break-before: always')
|
||||||
styles.append('display: block')
|
styles.append('display: block')
|
||||||
styles.append('margin: 0')
|
styles.append('margin: 0')
|
||||||
if styles:
|
elif tag.tag == 'i':
|
||||||
attrib['style'] = '; '.join(styles)
|
tag.tag = 'span'
|
||||||
|
tag.attrib['class'] = 'italic'
|
||||||
if tag.tag.lower() == 'font':
|
elif tag.tag == 'b':
|
||||||
|
tag.tag = 'span'
|
||||||
|
tag.attrib['class'] = 'bold'
|
||||||
|
elif tag.tag == 'font':
|
||||||
sz = tag.get('size', '').lower()
|
sz = tag.get('size', '').lower()
|
||||||
try:
|
try:
|
||||||
float(sz)
|
float(sz)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if sz in size_map.keys():
|
if sz in size_map.keys():
|
||||||
attrib['size'] = size_map[sz]
|
attrib['size'] = size_map[sz]
|
||||||
if 'filepos-id' in attrib:
|
elif tag.tag == 'img':
|
||||||
attrib['id'] = attrib.pop('filepos-id')
|
|
||||||
if 'filepos' in attrib:
|
|
||||||
filepos = int(attrib.pop('filepos'))
|
|
||||||
attrib['href'] = "#filepos%d" % filepos
|
|
||||||
if tag.tag == 'img':
|
|
||||||
recindex = None
|
recindex = None
|
||||||
for attr in self.IMAGE_ATTRS:
|
for attr in self.IMAGE_ATTRS:
|
||||||
recindex = attrib.pop(attr, None) or recindex
|
recindex = attrib.pop(attr, None) or recindex
|
||||||
if recindex is not None:
|
if recindex is not None:
|
||||||
attrib['src'] = 'images/%s.jpg' % recindex
|
attrib['src'] = 'images/%s.jpg' % recindex
|
||||||
|
if styles:
|
||||||
|
attrib['style'] = '; '.join(styles)
|
||||||
|
if 'filepos-id' in attrib:
|
||||||
|
attrib['id'] = attrib.pop('filepos-id')
|
||||||
|
if 'filepos' in attrib:
|
||||||
|
filepos = attrib.pop('filepos')
|
||||||
|
try:
|
||||||
|
attrib['href'] = "#filepos%d" % int(filepos)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
def create_opf(self, htmlfile, guide=None):
|
def create_opf(self, htmlfile, guide=None):
|
||||||
mi = self.book_header.exth.mi
|
mi = self.book_header.exth.mi
|
||||||
@ -325,7 +330,7 @@ class MobiReader(object):
|
|||||||
manifest = [(htmlfile, 'text/x-oeb1-document')]
|
manifest = [(htmlfile, 'text/x-oeb1-document')]
|
||||||
bp = os.path.dirname(htmlfile)
|
bp = os.path.dirname(htmlfile)
|
||||||
for i in getattr(self, 'image_names', []):
|
for i in getattr(self, 'image_names', []):
|
||||||
manifest.append((os.path.join(bp, 'images/', i), 'image/jpg'))
|
manifest.append((os.path.join(bp, 'images/', i), 'image/jpeg'))
|
||||||
|
|
||||||
opf.create_manifest(manifest)
|
opf.create_manifest(manifest)
|
||||||
opf.create_spine([os.path.basename(htmlfile)])
|
opf.create_spine([os.path.basename(htmlfile)])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user