diff --git a/src/calibre/ebooks/conversion/plugins/docx_input.py b/src/calibre/ebooks/conversion/plugins/docx_input.py index 71e93b45fd..0ebad740a7 100644 --- a/src/calibre/ebooks/conversion/plugins/docx_input.py +++ b/src/calibre/ebooks/conversion/plugins/docx_input.py @@ -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)() diff --git a/src/calibre/ebooks/docx/styles.py b/src/calibre/ebooks/docx/styles.py index 7b36a29325..944a80e565 100644 --- a/src/calibre/ebooks/docx/styles.py +++ b/src/calibre/ebooks/docx/styles.py @@ -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 diff --git a/src/calibre/ebooks/docx/to_html.py b/src/calibre/ebooks/docx/to_html.py index 4bbfe14426..36cfb6125a 100644 --- a/src/calibre/ebooks/docx/to_html.py +++ b/src/calibre/ebooks/docx/to_html.py @@ -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='') 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')) diff --git a/src/calibre/gui2/convert/docx_input.py b/src/calibre/gui2/convert/docx_input.py index 79f2a07ecb..d2048ebeb2 100644 --- a/src/calibre/gui2/convert/docx_input.py +++ b/src/calibre/gui2/convert/docx_input.py @@ -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) diff --git a/src/calibre/gui2/convert/docx_input.ui b/src/calibre/gui2/convert/docx_input.ui index 41948118dc..2d45e8f39c 100644 --- a/src/calibre/gui2/convert/docx_input.ui +++ b/src/calibre/gui2/convert/docx_input.ui @@ -21,6 +21,13 @@ + + + + Do not add a page after before every footnote + + +