diff --git a/src/calibre/ebooks/conversion/plugins/docx_input.py b/src/calibre/ebooks/conversion/plugins/docx_input.py index 37572a65e3..dc40dd526c 100644 --- a/src/calibre/ebooks/conversion/plugins/docx_input.py +++ b/src/calibre/ebooks/conversion/plugins/docx_input.py @@ -21,12 +21,13 @@ class DOCXInput(InputFormatPlugin): 'turns off that behavior.')), OptionRecommendation(name='docx_no_pagebreaks_between_notes', recommended_value=False, help=_('Do not insert a page break after every endnote.')), - + OptionRecommendation(name='docx_no_supsub_in_css', recommended_value=False, + help=_('Use top and bottom vertical-align values in stylesheet, instead of superscript and subscript.')), } recommendations = set([('page_breaks_before', '/', OptionRecommendation.MED)]) 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, notes_nopb=options.docx_no_pagebreaks_between_notes)() + return Convert(stream, detect_cover=not options.docx_no_cover, log=log, notes_nopb=options.docx_no_pagebreaks_between_notes, nosupsub=options.docx_no_supsub_in_css)() diff --git a/src/calibre/ebooks/docx/styles.py b/src/calibre/ebooks/docx/styles.py index 944a80e565..009bac4297 100644 --- a/src/calibre/ebooks/docx/styles.py +++ b/src/calibre/ebooks/docx/styles.py @@ -432,7 +432,7 @@ class Styles(object): h = hash(frozenset(css.iteritems())) return self.classes.get(h, (None, None))[0] - def generate_css(self, dest_dir, docx, notes_nopb): + def generate_css(self, dest_dir, docx, notes_nopb, nosupsub): ef = self.fonts.embed_fonts(dest_dir, docx) s = '''\ @@ -469,9 +469,14 @@ class Styles(object): p.index-entry { text-indent: 0pt; } p.index-entry a:visited { color: blue } p.index-entry a:hover { color: red } - ''' + if nosupsub: + s = s + '''\ + sup { vertical-align: top } + sub { vertical-align: bottom } + ''' + 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 7458d3b8e6..7cbf7c3b2b 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, notes_nopb=False): + def __init__(self, path_or_stream, dest_dir=None, log=None, detect_cover=True, notes_text=None, notes_nopb=False, nosupsub=False): self.docx = DOCX(path_or_stream, log=log) self.namespace = self.docx.namespace self.ms_pat = re.compile(r'\s{2,}') @@ -59,6 +59,7 @@ class Convert(object): self.detect_cover = detect_cover self.notes_text = notes_text or _('Notes') self.notes_nopb = notes_nopb + self.nosupsub = nosupsub self.dest_dir = dest_dir or os.getcwdu() self.mi = self.docx.metadata self.body = BODY() @@ -345,7 +346,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, self.notes_nopb) + css = self.styles.generate_css(self.dest_dir, self.docx, self.notes_nopb, self.nosupsub) 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 fdd0e13752..c9d97090f5 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_pagebreaks_between_notes']) + ['docx_no_cover', 'docx_no_pagebreaks_between_notes', 'docx_no_supsub_in_css']) 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 415d0c26e2..182a8acd8c 100644 --- a/src/calibre/gui2/convert/docx_input.ui +++ b/src/calibre/gui2/convert/docx_input.ui @@ -28,6 +28,13 @@ + + + + Use top and bottom as vertical-align values in stylesheet, instead of superscript and subscript + + +