mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
HTMLZ Output: Add option to use the book title as the filename for the html file inside the archive
This commit is contained in:
parent
61f9658f21
commit
1ac5c914f7
@ -37,6 +37,11 @@ class HTMLZOutput(OutputFormatPlugin):
|
|||||||
'external: Use an external CSS file that is linked in the document.\n'
|
'external: Use an external CSS file that is linked in the document.\n'
|
||||||
'inline: Place the CSS in the head section of the document.'
|
'inline: Place the CSS in the head section of the document.'
|
||||||
)),
|
)),
|
||||||
|
OptionRecommendation(name='htmlz_title_filename',
|
||||||
|
recommended_value=False, level=OptionRecommendation.LOW,
|
||||||
|
help=_('If set this option causes the file name of the html file'
|
||||||
|
' inside the htmlz archive to be based on the book title.')
|
||||||
|
),
|
||||||
])
|
])
|
||||||
|
|
||||||
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
||||||
@ -44,6 +49,7 @@ class HTMLZOutput(OutputFormatPlugin):
|
|||||||
from calibre.ebooks.oeb.base import OEB_IMAGES, SVG_MIME
|
from calibre.ebooks.oeb.base import OEB_IMAGES, SVG_MIME
|
||||||
from calibre.ebooks.metadata.opf2 import OPF, metadata_to_opf
|
from calibre.ebooks.metadata.opf2 import OPF, metadata_to_opf
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
|
from calibre.utils.filenames import ascii_filename
|
||||||
|
|
||||||
# HTML
|
# HTML
|
||||||
if opts.htmlz_css_type == 'inline':
|
if opts.htmlz_css_type == 'inline':
|
||||||
@ -59,7 +65,10 @@ class HTMLZOutput(OutputFormatPlugin):
|
|||||||
htmlizer = OEB2HTMLizer(log)
|
htmlizer = OEB2HTMLizer(log)
|
||||||
html = htmlizer.oeb2html(oeb_book, opts)
|
html = htmlizer.oeb2html(oeb_book, opts)
|
||||||
|
|
||||||
with open(os.path.join(tdir, u'index.html'), 'wb') as tf:
|
fname = u'index'
|
||||||
|
if opts.htmlz_title_filename:
|
||||||
|
fname = ascii_filename(unicode(oeb_book.metadata.title[0]))
|
||||||
|
with open(os.path.join(tdir, fname+u'.html'), 'wb') as tf:
|
||||||
tf.write(html)
|
tf.write(html)
|
||||||
|
|
||||||
# CSS
|
# CSS
|
||||||
|
@ -17,7 +17,8 @@ class PluginWidget(Widget, Ui_Form):
|
|||||||
ICON = I('mimetypes/html.png')
|
ICON = I('mimetypes/html.png')
|
||||||
|
|
||||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||||
Widget.__init__(self, parent, ['htmlz_css_type', 'htmlz_class_style'])
|
Widget.__init__(self, parent, ['htmlz_css_type', 'htmlz_class_style',
|
||||||
|
'htmlz_title_filename'])
|
||||||
self.db, self.book_id = db, book_id
|
self.db, self.book_id = db, book_id
|
||||||
for x in get_option('htmlz_css_type').option.choices:
|
for x in get_option('htmlz_css_type').option.choices:
|
||||||
self.opt_htmlz_css_type.addItem(x)
|
self.opt_htmlz_css_type.addItem(x)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="2" column="0">
|
<item row="3" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -27,6 +27,9 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QComboBox" name="opt_htmlz_class_style"/>
|
||||||
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -51,8 +54,12 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="2" column="0" colspan="2">
|
||||||
<widget class="QComboBox" name="opt_htmlz_class_style"/>
|
<widget class="QCheckBox" name="opt_htmlz_title_filename">
|
||||||
|
<property name="text">
|
||||||
|
<string>Use book &title as the filename for the HTML file inside the archive</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user