mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2611 (MemoryError Converting LIT to MOBI)
This commit is contained in:
parent
30af7f26db
commit
38e60f714b
@ -427,7 +427,7 @@ class MobiWriter(object):
|
|||||||
# borrowed from _generate_indxt
|
# borrowed from _generate_indxt
|
||||||
for i, child in enumerate(entries):
|
for i, child in enumerate(entries):
|
||||||
if not child.title or not child.title.strip():
|
if not child.title or not child.title.strip():
|
||||||
continue
|
child.title = _('Unnamed')
|
||||||
h = child.href
|
h = child.href
|
||||||
if h not in self._id_offsets:
|
if h not in self._id_offsets:
|
||||||
self._oeb.log.warning('Could not find TOC entry:', child.title)
|
self._oeb.log.warning('Could not find TOC entry:', child.title)
|
||||||
@ -869,21 +869,24 @@ class MobiWriter(object):
|
|||||||
self._last_toc_entry = None
|
self._last_toc_entry = None
|
||||||
ctoc = StringIO()
|
ctoc = StringIO()
|
||||||
|
|
||||||
def add_node(node, cls, title=None):
|
def add_node(node, cls):
|
||||||
t = node.title if title is None else title
|
t = node.title
|
||||||
if t and t.strip():
|
if not t:
|
||||||
t = t.strip()
|
t = _('Unnamed')
|
||||||
if not isinstance(t, unicode):
|
t = t.strip()
|
||||||
t = t.decode('utf-8', 'replace')
|
if not isinstance(t, unicode):
|
||||||
t = t.encode('utf-8')
|
t = t.decode('utf-8', 'replace')
|
||||||
self._last_toc_entry = t
|
t = t.encode('utf-8')
|
||||||
self._ctoc_map[node] = ctoc.tell()
|
self._last_toc_entry = t
|
||||||
self._ctoc_name_map[node] = t
|
self._ctoc_map[node] = ctoc.tell()
|
||||||
ctoc.write(decint(len(t), DECINT_FORWARD)+t)
|
self._ctoc_name_map[node] = t
|
||||||
|
ctoc.write(decint(len(t), DECINT_FORWARD)+t)
|
||||||
|
|
||||||
first = True
|
first = True
|
||||||
for child in toc.iter():
|
for child in toc.iter():
|
||||||
add_node(child, 'chapter')#, title='Title Page' if first else None)
|
if not child.title:
|
||||||
|
child.title = _('Unnamed')
|
||||||
|
add_node(child, 'chapter')
|
||||||
first = False
|
first = False
|
||||||
|
|
||||||
return align_block(ctoc.getvalue())
|
return align_block(ctoc.getvalue())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user