mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Edit Book: A new tool to transform book styling using easy to create rules.
For example, you can create rules to change colors in the book or to double the font size of all text in the book, etc. For details, see https://manual.calibre-ebook.com/edit.html#transforming-css-properties
This commit is contained in:
parent
acd87396d9
commit
2da3c9d30b
@ -375,6 +375,21 @@ Note that the algorithm can sometimes generate incorrect results, especially
|
||||
when single quotes at the start of contractions are involved. Accessed via
|
||||
:guilabel:`Tools->Smarten punctuation`.
|
||||
|
||||
Transforming CSS properties
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Create rules to transform the stying of the book. For example, create a rule
|
||||
to convert all red text to green or to double the font size of all text in the
|
||||
book or make text of a certain font family italic, etc.
|
||||
|
||||
Creating the rules is simple, the rules follow a natural language format, that
|
||||
looks like:
|
||||
|
||||
* If the property *color* is *red* *change* it to *green*
|
||||
* If the property *font-size* is *any value* *multiply* the value by *2*
|
||||
|
||||
Accessed via :guilabel:`Tools->Transform styles`.
|
||||
|
||||
Removing unused CSS rules
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -50,6 +50,7 @@ from calibre.utils.config import JSONConfig
|
||||
from calibre.utils.icu import numeric_sort_key
|
||||
|
||||
_diff_dialogs = []
|
||||
last_used_transform_rules = []
|
||||
|
||||
def get_container(*args, **kwargs):
|
||||
kwargs['tweak_mode'] = True
|
||||
@ -543,6 +544,34 @@ class Boss(QObject):
|
||||
self.rewind_savepoint()
|
||||
show_report(changed, self.current_metadata.title, report, parent or self.gui, self.show_current_diff)
|
||||
|
||||
def transform_styles(self):
|
||||
global last_used_transform_rules
|
||||
if not self.ensure_book(_('You must first open a book in order to transform styles.')):
|
||||
return
|
||||
from calibre.gui2.css_transform_rules import RulesDialog
|
||||
from calibre.ebooks.css_transform_rules import transform_container
|
||||
d = RulesDialog(self.gui)
|
||||
d.rules = last_used_transform_rules
|
||||
ret = d.exec_()
|
||||
last_used_transform_rules = d.rules
|
||||
if ret != d.Accepted:
|
||||
return
|
||||
with BusyCursor():
|
||||
self.add_savepoint(_('Before style transformation'))
|
||||
try:
|
||||
changed = transform_container(current_container(), last_used_transform_rules)
|
||||
except:
|
||||
self.rewind_savepoint()
|
||||
raise
|
||||
if changed:
|
||||
self.apply_container_update_to_gui()
|
||||
if not changed:
|
||||
self.rewind_savepoint()
|
||||
info_dialog(self.gui, _('No changes'), _(
|
||||
'No styles were changed.'), show=True)
|
||||
return
|
||||
self.show_current_diff()
|
||||
|
||||
def manage_fonts(self):
|
||||
self.commit_all_editors_to_container()
|
||||
self.gui.manage_fonts.display()
|
||||
|
@ -392,6 +392,8 @@ class Main(MainWindow):
|
||||
'Check external links in the book'))
|
||||
self.action_compress_images = treg('compress-image.png', _('Compress &images losslessly'), self.boss.compress_images, 'compress-images', (), _(
|
||||
'Compress images losslessly'))
|
||||
self.action_transform_styles = treg('wizard.png', _('Transform &styles'), self.boss.transform_styles, 'transform-styles', (), _(
|
||||
'Transform styles used in the book'))
|
||||
|
||||
def ereg(icon, text, target, sid, keys, description):
|
||||
return reg(icon, text, partial(self.boss.editor_action, target), sid, keys, description)
|
||||
@ -543,6 +545,7 @@ class Main(MainWindow):
|
||||
e.addAction(self.action_compress_images)
|
||||
e.addAction(self.action_smarten_punctuation)
|
||||
e.addAction(self.action_remove_unused_css)
|
||||
e.addAction(self.action_transform_styles)
|
||||
e.addAction(self.action_fix_html_all)
|
||||
e.addAction(self.action_pretty_all)
|
||||
e.addAction(self.action_rationalize_folders)
|
||||
|
Loading…
x
Reference in New Issue
Block a user