mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #1195 (First entry in TOC not created properly with html2epub)
This commit is contained in:
parent
ceecd7961c
commit
731b76779b
@ -177,7 +177,6 @@ class HTMLFile(object):
|
|||||||
raise IgnoreFile(msg, err.errno)
|
raise IgnoreFile(msg, err.errno)
|
||||||
|
|
||||||
self.is_binary = not bool(self.HTML_PAT.search(src[:1024]))
|
self.is_binary = not bool(self.HTML_PAT.search(src[:1024]))
|
||||||
self.title = None
|
|
||||||
if not self.is_binary:
|
if not self.is_binary:
|
||||||
if encoding is None:
|
if encoding is None:
|
||||||
encoding = xml_to_unicode(src[:4096], verbose=verbose)[-1]
|
encoding = xml_to_unicode(src[:4096], verbose=verbose)[-1]
|
||||||
@ -187,7 +186,7 @@ class HTMLFile(object):
|
|||||||
|
|
||||||
src = src.decode(encoding, 'replace')
|
src = src.decode(encoding, 'replace')
|
||||||
match = self.TITLE_PAT.search(src)
|
match = self.TITLE_PAT.search(src)
|
||||||
self.title = match.group(1) if match is not None else None
|
self.title = match.group(1) if match is not None else self.title
|
||||||
self.find_links(src)
|
self.find_links(src)
|
||||||
|
|
||||||
|
|
||||||
@ -650,7 +649,6 @@ class Processor(Parser):
|
|||||||
elem.set('id', id)
|
elem.set('id', id)
|
||||||
add_item(href, id, text, toc, type='chapter')
|
add_item(href, id, text, toc, type='chapter')
|
||||||
|
|
||||||
|
|
||||||
referrer = toc
|
referrer = toc
|
||||||
if self.htmlfile.referrer is not None:
|
if self.htmlfile.referrer is not None:
|
||||||
try:
|
try:
|
||||||
@ -662,14 +660,13 @@ class Processor(Parser):
|
|||||||
break
|
break
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
if referrer is toc:
|
||||||
|
text = self.htmlfile.title
|
||||||
|
name = self.htmlfile_map[self.htmlfile.referrer]
|
||||||
|
href = 'content/'+name
|
||||||
|
referrer = add_item(href, None, text, toc)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if referrer.href != href: # Happens for root file
|
|
||||||
target = add_item(href, None, unicode(self.htmlfile.title), referrer, type='file')
|
|
||||||
|
|
||||||
# Add links to TOC
|
# Add links to TOC
|
||||||
if int(self.opts.max_toc_links) > 0:
|
if int(self.opts.max_toc_links) > 0:
|
||||||
for link in list(self.LINKS_PATH(self.root))[:self.opts.max_toc_links]:
|
for link in list(self.LINKS_PATH(self.root))[:self.opts.max_toc_links]:
|
||||||
@ -682,10 +679,9 @@ class Processor(Parser):
|
|||||||
href, fragment = parts[0], None
|
href, fragment = parts[0], None
|
||||||
if len(parts) > 1:
|
if len(parts) > 1:
|
||||||
fragment = parts[1]
|
fragment = parts[1]
|
||||||
if self.htmlfile.referrer is not None:
|
add_item(href, fragment, text, referrer)
|
||||||
name = self.htmlfile_map[self.htmlfile.referrer.path]
|
|
||||||
add_item(href, fragment, text, target)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def preprocess_css(cls, css, dpi=96):
|
def preprocess_css(cls, css, dpi=96):
|
||||||
def rescale(match):
|
def rescale(match):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user