Implement a --page-breaks-before option

This commit is contained in:
Kovid Goyal 2009-04-25 14:38:23 -07:00
parent 0d07ad2610
commit d253544a1f
3 changed files with 17 additions and 1 deletions

View File

@ -128,7 +128,7 @@ def add_pipeline_options(parser, plumber):
[
'dont_split_on_page_breaks', 'chapter', 'chapter_mark',
'prefer_metadata_cover', 'remove_first_image',
'insert_comments',
'insert_comments', 'page_breaks_before',
]
),

View File

@ -227,6 +227,14 @@ OptionRecommendation(name='extra_css',
'rules.')
),
OptionRecommendation(name='page_breaks_before',
recommended_value="//*[name()='h1' or name()='h2']",
level=OptionRecommendation.LOW,
help=_('An XPath expression. Page breaks are inserted '
'before the specified elements.')
),
OptionRecommendation(name='margin_top',
recommended_value=5.0, level=OptionRecommendation.LOW,
help=_('Set the top margin in pts. Default is %default')),

View File

@ -45,6 +45,14 @@ class DetectStructure(object):
if not node.title or regexp.search(node.title) is not None:
self.oeb.toc.remove(node)
if opts.page_breaks_before is not None:
pb_xpath = XPath(opts.page_breaks_before)
for item in oeb.spine:
for elem in pb_xpath(item.data):
style = elem.get('style', '')
if style:
style += '; '
elem.set('style', style+'page-break-before:always')
def detect_chapters(self):
self.detected_chapters = []