mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Sync to pluginize
This commit is contained in:
commit
7ce53a941e
@ -128,7 +128,7 @@ def add_pipeline_options(parser, plumber):
|
|||||||
[
|
[
|
||||||
'dont_split_on_page_breaks', 'chapter', 'chapter_mark',
|
'dont_split_on_page_breaks', 'chapter', 'chapter_mark',
|
||||||
'prefer_metadata_cover', 'remove_first_image',
|
'prefer_metadata_cover', 'remove_first_image',
|
||||||
'insert_comments',
|
'insert_comments', 'page_breaks_before',
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -227,6 +227,14 @@ OptionRecommendation(name='extra_css',
|
|||||||
'rules.')
|
'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',
|
OptionRecommendation(name='margin_top',
|
||||||
recommended_value=5.0, level=OptionRecommendation.LOW,
|
recommended_value=5.0, level=OptionRecommendation.LOW,
|
||||||
help=_('Set the top margin in pts. Default is %default')),
|
help=_('Set the top margin in pts. Default is %default')),
|
||||||
|
@ -26,10 +26,17 @@ def sanitize_head(match):
|
|||||||
def chap_head(match):
|
def chap_head(match):
|
||||||
chap = match.group('chap')
|
chap = match.group('chap')
|
||||||
title = match.group('title')
|
title = match.group('title')
|
||||||
|
<<<<<<< TREE
|
||||||
if not title:
|
if not title:
|
||||||
return '<h1>'+chap+'</h1><br/>\n'
|
return '<h1>'+chap+'</h1><br/>\n'
|
||||||
else:
|
else:
|
||||||
return '<h1>'+chap+'<br/>\n'+title+'</h1><br/>\n'
|
return '<h1>'+chap+'<br/>\n'+title+'</h1><br/>\n'
|
||||||
|
=======
|
||||||
|
if not title:
|
||||||
|
return '<h1>'+chap+'</h1><br/>'
|
||||||
|
else:
|
||||||
|
return '<h1>'+chap+'<br/>'+title+'</h1><br/>'
|
||||||
|
>>>>>>> MERGE-SOURCE
|
||||||
|
|
||||||
def wrap_lines(match):
|
def wrap_lines(match):
|
||||||
ital = match.group('ital')
|
ital = match.group('ital')
|
||||||
@ -117,7 +124,6 @@ class HTMLPreProcessor(object):
|
|||||||
|
|
||||||
# Have paragraphs show better
|
# Have paragraphs show better
|
||||||
(re.compile(r'<br.*?>'), lambda match : '<p>'),
|
(re.compile(r'<br.*?>'), lambda match : '<p>'),
|
||||||
|
|
||||||
# Clean up spaces
|
# Clean up spaces
|
||||||
(re.compile(u'(?<=[\.,:;\?!”"\'])[\s^ ]*(?=<)'), lambda match: ' '),
|
(re.compile(u'(?<=[\.,:;\?!”"\'])[\s^ ]*(?=<)'), lambda match: ' '),
|
||||||
# Add space before and after italics
|
# Add space before and after italics
|
||||||
@ -154,6 +160,7 @@ class HTMLPreProcessor(object):
|
|||||||
def __call__(self, html, remove_special_chars=None):
|
def __call__(self, html, remove_special_chars=None):
|
||||||
if remove_special_chars is not None:
|
if remove_special_chars is not None:
|
||||||
html = remove_special_chars.sub('', html)
|
html = remove_special_chars.sub('', html)
|
||||||
|
html = html.replace('\0', '')
|
||||||
if self.is_baen(html):
|
if self.is_baen(html):
|
||||||
rules = []
|
rules = []
|
||||||
elif self.is_book_designer(html):
|
elif self.is_book_designer(html):
|
||||||
|
@ -941,7 +941,10 @@ class Manifest(object):
|
|||||||
href = urlunparse(purl)
|
href = urlunparse(purl)
|
||||||
path, frag = urldefrag(href)
|
path, frag = urldefrag(href)
|
||||||
if not path:
|
if not path:
|
||||||
|
if frag:
|
||||||
return '#'.join((self.href, frag))
|
return '#'.join((self.href, frag))
|
||||||
|
else:
|
||||||
|
return self.href
|
||||||
if '/' not in self.href:
|
if '/' not in self.href:
|
||||||
return href
|
return href
|
||||||
dirname = os.path.dirname(self.href)
|
dirname = os.path.dirname(self.href)
|
||||||
|
@ -45,6 +45,14 @@ class DetectStructure(object):
|
|||||||
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.oeb.toc.remove(node)
|
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):
|
def detect_chapters(self):
|
||||||
self.detected_chapters = []
|
self.detected_chapters = []
|
||||||
@ -102,6 +110,7 @@ class DetectStructure(object):
|
|||||||
play_order=self.oeb.toc.next_play_order())
|
play_order=self.oeb.toc.next_play_order())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def elem_to_link(self, item, elem, counter):
|
def elem_to_link(self, item, elem, counter):
|
||||||
text = u' '.join([t.strip() for t in elem.xpath('descendant::text()')])
|
text = u' '.join([t.strip() for t in elem.xpath('descendant::text()')])
|
||||||
text = text[:100].strip()
|
text = text[:100].strip()
|
||||||
|
@ -158,6 +158,9 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
def set_cover(self):
|
def set_cover(self):
|
||||||
row = self.formats.currentRow()
|
row = self.formats.currentRow()
|
||||||
fmt = self.formats.item(row)
|
fmt = self.formats.item(row)
|
||||||
|
if fmt is None:
|
||||||
|
if self.formats.count() == 1:
|
||||||
|
fmt = self.formats.item(0)
|
||||||
if fmt is None:
|
if fmt is None:
|
||||||
error_dialog(self, _('No format selected'),
|
error_dialog(self, _('No format selected'),
|
||||||
_('No format selected')).exec_()
|
_('No format selected')).exec_()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user