From 0c8013c5787a38748f569835972b275defa7477d Mon Sep 17 00:00:00 2001 From: m4mmon Date: Sun, 20 Dec 2015 22:08:12 +0100 Subject: [PATCH 1/2] Add option to use top/bottom as css property vertical-align instead of superscript/subscript --- src/calibre/ebooks/conversion/plugins/docx_input.py | 5 +++-- src/calibre/ebooks/docx/styles.py | 9 +++++++-- src/calibre/ebooks/docx/to_html.py | 5 +++-- src/calibre/gui2/convert/docx_input.py | 2 +- src/calibre/gui2/convert/docx_input.ui | 7 +++++++ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/docx_input.py b/src/calibre/ebooks/conversion/plugins/docx_input.py index 37572a6..dc40dd5 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 944a80e..009bac4 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 7458d3b..7cbf7c3 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 fdd0e13..c9d9709 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 415d0c2..182a8ac 100644 --- a/src/calibre/gui2/convert/docx_input.ui +++ b/src/calibre/gui2/convert/docx_input.ui @@ -29,6 +29,13 @@ + + + Use top and bottom as vertical-align values in stylesheet, instead of superscript and subscript + + + + Qt::Vertical -- 1.8.3.msysgit.0 From 2eff834f6829efbf5a02200000dea11c4e66c964 Mon Sep 17 00:00:00 2001 From: m4mmon Date: Sun, 20 Dec 2015 22:35:15 +0100 Subject: [PATCH 2/2] Add option to use top/bottom as css property vertical-align instead of superscript/subscript --- src/calibre/ebooks/docx/to_html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/ebooks/docx/to_html.py b/src/calibre/ebooks/docx/to_html.py index 7cbf7c3..de6dbec 100644 --- a/src/calibre/ebooks/docx/to_html.py +++ b/src/calibre/ebooks/docx/to_html.py @@ -629,7 +629,7 @@ class Convert(object): elif self.namespace.is_tag(child, 'w:footnoteReference') or self.namespace.is_tag(child, 'w:endnoteReference'): anchor, name = self.footnotes.get_ref(child) if anchor and name: - l = SUP(A(name, href='#' + anchor, title=name), id='back_%s' % anchor) + l = A(SUP(name, id='back_%s' % anchor), href='#' + anchor, title=name) l.set('class', 'noteref') text.add_elem(l) ans.append(text.elem) -- 1.8.3.msysgit.0