Allow customizing the html to zip plugin to add resources outside the html root folder

This commit is contained in:
Kovid Goyal 2023-05-29 10:41:53 +05:30
parent 3d96e98528
commit 83a1fef4d6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -61,6 +61,8 @@ every time you add an HTML file to the library.\
recs.append(['input_encoding', enc, OptionRecommendation.HIGH]) recs.append(['input_encoding', enc, OptionRecommendation.HIGH])
if settings.get('breadth_first'): if settings.get('breadth_first'):
recs.append(['breadth_first', True, OptionRecommendation.HIGH]) recs.append(['breadth_first', True, OptionRecommendation.HIGH])
if settings.get('allow_local_files_outside_root'):
recs.append(['allow_local_files_outside_root', True, OptionRecommendation.HIGH])
gui_convert(htmlfile, tdir, recs, abort_after_input_dump=True) gui_convert(htmlfile, tdir, recs, abort_after_input_dump=True)
of = self.temporary_file('_plugin_html2zip.zip') of = self.temporary_file('_plugin_html2zip.zip')
tdir = os.path.join(tdir, 'input') tdir = os.path.join(tdir, 'input')
@ -103,6 +105,7 @@ every time you add an HTML file to the library.\
help_text = self.customization_help(gui=True) help_text = self.customization_help(gui=True)
help_text = QLabel(help_text, config_dialog) help_text = QLabel(help_text, config_dialog)
help_text.setWordWrap(True) help_text.setWordWrap(True)
help_text.setMinimumWidth(300)
help_text.setTextInteractionFlags(Qt.TextInteractionFlag.LinksAccessibleByMouse | Qt.TextInteractionFlag.LinksAccessibleByKeyboard) help_text.setTextInteractionFlags(Qt.TextInteractionFlag.LinksAccessibleByMouse | Qt.TextInteractionFlag.LinksAccessibleByKeyboard)
help_text.setOpenExternalLinks(True) help_text.setOpenExternalLinks(True)
v.addWidget(help_text) v.addWidget(help_text)
@ -111,11 +114,20 @@ every time you add an HTML file to the library.\
' calibre does it depth first, i.e. if file A links to B and ' ' calibre does it depth first, i.e. if file A links to B and '
' C, but B links to D, the files are added in the order A, B, D, C. ' ' C, but B links to D, the files are added in the order A, B, D, C. '
' With this option, they will instead be added as A, B, C, D')) ' With this option, they will instead be added as A, B, C, D'))
lr = QCheckBox(_('Allow resources outside the HTML file root folder'))
from calibre.customize.ui import plugin_for_input_format
hi = plugin_for_input_format('html')
for opt in hi.options:
if opt.option.name == 'allow_local_files_outside_root':
lr.setToolTip(opt.help)
break
settings = self.parse_my_settings(plugin_customization(self)) settings = self.parse_my_settings(plugin_customization(self))
bf.setChecked(bool(settings.get('breadth_first'))) bf.setChecked(bool(settings.get('breadth_first')))
lr.setChecked(bool(settings.get('allow_local_files_outside_root')))
sc = QLineEdit(str(settings.get('encoding', '')), config_dialog) sc = QLineEdit(str(settings.get('encoding', '')), config_dialog)
v.addWidget(sc) v.addWidget(sc)
v.addWidget(bf) v.addWidget(bf)
v.addWidget(lr)
v.addWidget(button_box) v.addWidget(button_box)
size_dialog() size_dialog()
config_dialog.exec() config_dialog.exec()
@ -127,6 +139,8 @@ every time you add an HTML file to the library.\
settings['encoding'] = enc settings['encoding'] = enc
if bf.isChecked(): if bf.isChecked():
settings['breadth_first'] = True settings['breadth_first'] = True
if lr.isChecked():
settings['allow_local_files_outside_root'] = True
customize_plugin(self, json.dumps(settings, ensure_ascii=True)) customize_plugin(self, json.dumps(settings, ensure_ascii=True))
return config_dialog.result() return config_dialog.result()