mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #3377 (--toc-filter only removes alternate entries)
This commit is contained in:
parent
5f6c330901
commit
707f0ffa0c
@ -237,14 +237,14 @@ class HTMLPreProcessor(object):
|
|||||||
(re.compile(getattr(self.extra_opts, 'footer_regex')), lambda match : '')
|
(re.compile(getattr(self.extra_opts, 'footer_regex')), lambda match : '')
|
||||||
)
|
)
|
||||||
|
|
||||||
end_rules = []
|
end_rules = []
|
||||||
if getattr(self.extra_opts, 'unwrap_factor', None):
|
if getattr(self.extra_opts, 'unwrap_factor', None):
|
||||||
length = line_length(html, getattr(self.extra_opts, 'unwrap_factor'))
|
length = line_length(html, getattr(self.extra_opts, 'unwrap_factor'))
|
||||||
if length:
|
if length:
|
||||||
end_rules.append(
|
end_rules.append(
|
||||||
# Un wrap using punctuation
|
# Un wrap using punctuation
|
||||||
(re.compile(r'(?<=.{%i}[a-z\.,;:)-IA])\s*(?P<ital></(i|b|u)>)?\s*(<p.*?>)\s*(?=(<(i|b|u)>)?\s*[\w\d(])' % length, re.UNICODE), wrap_lines),
|
(re.compile(r'(?<=.{%i}[a-z\.,;:)-IA])\s*(?P<ital></(i|b|u)>)?\s*(<p.*?>)\s*(?=(<(i|b|u)>)?\s*[\w\d(])' % length, re.UNICODE), wrap_lines),
|
||||||
)
|
)
|
||||||
|
|
||||||
for rule in self.PREPROCESS + pre_rules + rules + end_rules:
|
for rule in self.PREPROCESS + pre_rules + rules + end_rules:
|
||||||
html = rule[0].sub(rule[1], html)
|
html = rule[0].sub(rule[1], html)
|
||||||
|
@ -48,8 +48,10 @@ class DetectStructure(object):
|
|||||||
|
|
||||||
if opts.toc_filter is not None:
|
if opts.toc_filter is not None:
|
||||||
regexp = re.compile(opts.toc_filter)
|
regexp = re.compile(opts.toc_filter)
|
||||||
for node in self.oeb.toc.iter():
|
for node in list(self.oeb.toc.iter()):
|
||||||
if not node.title or regexp.search(node.title) is not None:
|
if not node.title or regexp.search(node.title) is not None:
|
||||||
|
self.log('Filtering', node.title if node.title else\
|
||||||
|
'empty node', 'from TOC')
|
||||||
self.oeb.toc.remove(node)
|
self.oeb.toc.remove(node)
|
||||||
|
|
||||||
if opts.page_breaks_before is not None:
|
if opts.page_breaks_before is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user