HTMLZ Output: Add option to use the book title as the filename for the html file inside the archive

This commit is contained in:
Kovid Goyal 2012-07-10 23:33:33 +05:30
parent 61f9658f21
commit 1ac5c914f7
3 changed files with 22 additions and 5 deletions

View File

@ -37,6 +37,11 @@ class HTMLZOutput(OutputFormatPlugin):
'external: Use an external CSS file that is linked in the document.\n'
'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):
@ -44,6 +49,7 @@ class HTMLZOutput(OutputFormatPlugin):
from calibre.ebooks.oeb.base import OEB_IMAGES, SVG_MIME
from calibre.ebooks.metadata.opf2 import OPF, metadata_to_opf
from calibre.utils.zipfile import ZipFile
from calibre.utils.filenames import ascii_filename
# HTML
if opts.htmlz_css_type == 'inline':
@ -59,7 +65,10 @@ class HTMLZOutput(OutputFormatPlugin):
htmlizer = OEB2HTMLizer(log)
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)
# CSS

View File

@ -17,7 +17,8 @@ class PluginWidget(Widget, Ui_Form):
ICON = I('mimetypes/html.png')
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
for x in get_option('htmlz_css_type').option.choices:
self.opt_htmlz_css_type.addItem(x)

View File

@ -14,7 +14,7 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -27,6 +27,9 @@
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="opt_htmlz_class_style"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
@ -51,8 +54,12 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="opt_htmlz_class_style"/>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="opt_htmlz_title_filename">
<property name="text">
<string>Use book &amp;title as the filename for the HTML file inside the archive</string>
</property>
</widget>
</item>
</layout>
</widget>