mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix regression in TOC generation when creating EPUB. --toc-threshold now works and TOC entries created from links with only a fragment also work.
This commit is contained in:
parent
5dac2771b1
commit
651d609784
@ -100,7 +100,7 @@ to auto-generate a Table of Contents.
|
||||
toc('no_chapters_in_toc', ['--no-chapters-in-toc'], default=False,
|
||||
help=_("Don't add auto-detected chapters to the Table of Contents."))
|
||||
toc('toc_threshold', ['--toc-threshold'], default=6,
|
||||
help=_('If fewer than this number of chapters is detected, then links are added to the Table of Contents.'))
|
||||
help=_('If fewer than this number of chapters is detected, then links are added to the Table of Contents. Default: %default'))
|
||||
toc('level1_toc', ['--level1-toc'], default=None,
|
||||
help=_('XPath expression that specifies all tags that should be added to the Table of Contents at level one. If this is specified, it takes precedence over other forms of auto-detection.'))
|
||||
toc('level2_toc', ['--level2-toc'], default=None,
|
||||
|
@ -641,7 +641,6 @@ class Processor(Parser):
|
||||
if len(toc) > 0:
|
||||
return
|
||||
# Add chapters to TOC
|
||||
|
||||
if not self.opts.no_chapters_in_toc:
|
||||
for elem in getattr(self, 'detected_chapters', []):
|
||||
text = (u''.join(elem.xpath('string()'))).strip()
|
||||
@ -651,6 +650,8 @@ class Processor(Parser):
|
||||
elem.set('id', id)
|
||||
add_item(href, id, text, toc, type='chapter')
|
||||
|
||||
if len(list(toc.flat())) >= self.opts.toc_threshold:
|
||||
return
|
||||
referrer = toc
|
||||
if self.htmlfile.referrer is not None:
|
||||
try:
|
||||
@ -668,7 +669,6 @@ class Processor(Parser):
|
||||
href = 'content/'+name
|
||||
referrer = add_item(href, None, text, toc)
|
||||
|
||||
|
||||
# Add links to TOC
|
||||
if int(self.opts.max_toc_links) > 0:
|
||||
for link in list(self.LINKS_PATH(self.root))[:self.opts.max_toc_links]:
|
||||
@ -676,6 +676,9 @@ class Processor(Parser):
|
||||
if text:
|
||||
href = link.get('href', '')
|
||||
if href and not (href.startswith('http://') or href.startswith('https://')):
|
||||
href = href.strip()
|
||||
if href.startswith('#'):
|
||||
href = self.htmlfile_map[self.htmlfile.path] + href
|
||||
href = 'content/'+href
|
||||
parts = href.split('#')
|
||||
href, fragment = parts[0], None
|
||||
@ -683,7 +686,6 @@ class Processor(Parser):
|
||||
fragment = parts[1]
|
||||
add_item(href, fragment, text, referrer)
|
||||
|
||||
|
||||
@classmethod
|
||||
def preprocess_css(cls, css, dpi=96):
|
||||
def rescale(match):
|
||||
|
@ -32,6 +32,14 @@ class TOC(list):
|
||||
self.play_order = play_order
|
||||
self.type = type
|
||||
|
||||
def __str__(self):
|
||||
lines = ['TOC: %s#%s'%(self.href, self.fragment)]
|
||||
for child in self:
|
||||
c = str(child).splitlines()
|
||||
for l in c:
|
||||
lines.append('\t'+l)
|
||||
return '\n'.join(lines)
|
||||
|
||||
def count(self, type):
|
||||
return len([i for i in self.flat() if i.type == type])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user