mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add option to use top/bottom as css property vertical-align instead of superscript/subscript
This commit is contained in:
parent
752a0aec90
commit
031dce78f5
@ -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)()
|
||||
|
||||
|
@ -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
|
||||
|
@ -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='<!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, 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'))
|
||||
|
@ -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)
|
||||
|
||||
|
@ -28,6 +28,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="opt_docx_no_supsub_in_css">
|
||||
<property name="text">
|
||||
<string>Use top and bottom as vertical-align values in stylesheet, instead of superscript and subscript</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
Loading…
x
Reference in New Issue
Block a user