mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: Fix import of DOCX files that contain no Table of Contents not working. Fixes #1327522 [error editor while importing docx](https://bugs.launchpad.net/calibre/+bug/1327522)
This commit is contained in:
parent
7f97e4213a
commit
0b0f6abe42
@ -343,8 +343,11 @@ class Convert(object):
|
||||
opf.create_spine(['index.html'])
|
||||
if self.cover_image is not None:
|
||||
opf.guide.set_cover(self.cover_image)
|
||||
with open(os.path.join(self.dest_dir, 'metadata.opf'), 'wb') as of, open(os.path.join(self.dest_dir, 'toc.ncx'), 'wb') as ncx:
|
||||
toc_file = os.path.join(self.dest_dir, 'toc.ncx')
|
||||
with open(os.path.join(self.dest_dir, 'metadata.opf'), 'wb') as of, open(toc_file, 'wb') as ncx:
|
||||
opf.render(of, ncx, 'toc.ncx')
|
||||
if os.path.getsize(toc_file) == 0:
|
||||
os.remove(toc_file)
|
||||
return os.path.join(self.dest_dir, 'metadata.opf')
|
||||
|
||||
def read_block_anchors(self, doc):
|
||||
|
@ -661,7 +661,7 @@ class Container(object): # {{{
|
||||
package.append(item)
|
||||
return item
|
||||
|
||||
def generate_item(self, name, id_prefix=None, media_type=None):
|
||||
def generate_item(self, name, id_prefix=None, media_type=None, unique_href=True):
|
||||
'''Add an item to the manifest with href derived from the given
|
||||
name. Ensures uniqueness of href and id automatically. Returns
|
||||
generated item.'''
|
||||
@ -681,6 +681,7 @@ class Container(object): # {{{
|
||||
def exists(h):
|
||||
return self.exists(self.href_to_name(h, self.opf_name))
|
||||
|
||||
if unique_href:
|
||||
c = 0
|
||||
while href in all_names or exists(href):
|
||||
c += 1
|
||||
|
@ -23,10 +23,10 @@ def auto_fill_manifest(container):
|
||||
|
||||
for name, mt in container.mime_map.iteritems():
|
||||
if name not in manifest_name_map and not container.ok_to_be_unmanifested(name):
|
||||
mitem = container.generate_item(name)
|
||||
mitem = container.generate_item(name, unique_href=False)
|
||||
gname = container.href_to_name(mitem.get('href'), container.opf_name)
|
||||
if gname != name:
|
||||
raise ValueError('This should never happen (gname=%r, name=%r)' % (gname, name))
|
||||
raise ValueError('This should never happen (gname=%r, name=%r, href=%r)' % (gname, name, mitem.get('href')))
|
||||
manifest_name_map[name] = mitem.get('id')
|
||||
manifest_id_map[mitem.get('id')] = name
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user