mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DOCX Input: Add option to not insert page breaks after endnotes
This commit is contained in:
parent
b4a67e68ec
commit
be4d44c3d8
@ -19,6 +19,9 @@ class DOCXInput(InputFormatPlugin):
|
||||
help=_('Normally, if a large image is present at the start of the document that looks like a cover, '
|
||||
'it will be removed from the document and used as the cover for created ebook. This option '
|
||||
'turns off that behavior.')),
|
||||
OptionRecommendation(name='docx_notes_nopb', recommended_value=False,
|
||||
help=_('Normally, a page break is added after every footnote, '
|
||||
'This option turns off that behavior.')),
|
||||
|
||||
}
|
||||
|
||||
@ -26,5 +29,5 @@ class DOCXInput(InputFormatPlugin):
|
||||
|
||||
def convert(self, stream, options, file_ext, log, accelerators):
|
||||
from calibre.ebooks.docx.to_html import Convert
|
||||
return Convert(stream, detect_cover=not options.docx_no_cover, log=log)()
|
||||
return Convert(stream, detect_cover=not options.docx_no_cover, log=log, notes_nopb=options.docx_notes_nopb)()
|
||||
|
||||
|
@ -432,10 +432,10 @@ class Styles(object):
|
||||
h = hash(frozenset(css.iteritems()))
|
||||
return self.classes.get(h, (None, None))[0]
|
||||
|
||||
def generate_css(self, dest_dir, docx):
|
||||
def generate_css(self, dest_dir, docx, notes_nopb):
|
||||
ef = self.fonts.embed_fonts(dest_dir, docx)
|
||||
prefix = textwrap.dedent(
|
||||
'''\
|
||||
|
||||
s = '''\
|
||||
body { font-family: %s; font-size: %s; color: %s }
|
||||
|
||||
/* In word all paragraphs have zero margins unless explicitly specified in a style */
|
||||
@ -456,8 +456,12 @@ class Styles(object):
|
||||
|
||||
dl.notes dt a { text-decoration: none }
|
||||
|
||||
dl.notes dd { page-break-after: always }
|
||||
'''
|
||||
|
||||
if not notes_nopb:
|
||||
s = s + 'dl.notes dd { page-break-after: always }'
|
||||
|
||||
s = s + '''\
|
||||
dl.notes dd:last-of-type { page-break-after: avoid }
|
||||
|
||||
span.tab { white-space: pre }
|
||||
@ -466,7 +470,9 @@ class Styles(object):
|
||||
p.index-entry a:visited { color: blue }
|
||||
p.index-entry a:hover { color: red }
|
||||
|
||||
''') % (self.body_font_family, self.body_font_size, self.body_color)
|
||||
'''
|
||||
|
||||
prefix = textwrap.dedent(s) % (self.body_font_family, self.body_font_size, self.body_color)
|
||||
if ef:
|
||||
prefix = ef + '\n' + prefix
|
||||
|
||||
|
@ -50,7 +50,7 @@ def html_lang(docx_lang):
|
||||
|
||||
class Convert(object):
|
||||
|
||||
def __init__(self, path_or_stream, dest_dir=None, log=None, detect_cover=True, notes_text=None):
|
||||
def __init__(self, path_or_stream, dest_dir=None, log=None, detect_cover=True, notes_text=None, notes_nopb=False):
|
||||
self.docx = DOCX(path_or_stream, log=log)
|
||||
self.namespace = self.docx.namespace
|
||||
self.ms_pat = re.compile(r'\s{2,}')
|
||||
@ -58,6 +58,7 @@ class Convert(object):
|
||||
self.log = self.docx.log
|
||||
self.detect_cover = detect_cover
|
||||
self.notes_text = notes_text or _('Notes')
|
||||
self.notes_nopb = notes_nopb
|
||||
self.dest_dir = dest_dir or os.getcwdu()
|
||||
self.mi = self.docx.metadata
|
||||
self.body = BODY()
|
||||
@ -340,7 +341,7 @@ class Convert(object):
|
||||
raw = html.tostring(self.html, encoding='utf-8', doctype='<!DOCTYPE html>')
|
||||
with open(os.path.join(self.dest_dir, 'index.html'), 'wb') as f:
|
||||
f.write(raw)
|
||||
css = self.styles.generate_css(self.dest_dir, self.docx)
|
||||
css = self.styles.generate_css(self.dest_dir, self.docx, self.notes_nopb)
|
||||
if css:
|
||||
with open(os.path.join(self.dest_dir, 'docx.css'), 'wb') as f:
|
||||
f.write(css.encode('utf-8'))
|
||||
|
@ -18,6 +18,6 @@ class PluginWidget(Widget, Ui_Form):
|
||||
|
||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||
Widget.__init__(self, parent,
|
||||
['docx_no_cover', ])
|
||||
['docx_no_cover', 'docx_notes_nopb'])
|
||||
self.initialize_options(get_option, get_help, db, book_id)
|
||||
|
||||
|
@ -21,6 +21,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="opt_docx_notes_nopb">
|
||||
<property name="text">
|
||||
<string>Do not add a page after before every footnote</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
Loading…
x
Reference in New Issue
Block a user