View Single Post
Old 11-22-2021, 04:13 AM   #1
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,106
Karma: 1954138
Join Date: Aug 2015
Device: Kindle
[Editor Plugin] Editor Chains

For people familiar with the Action Chains plugin, this is a similar plugin for the calibre editor. It allows the user to chain multiple actions and run them together.

Currently Available Actions:
  • Plugin Actions
    1. Tag Actions: Allows the user to apply a variety of actions on tags, which are located based on range of tag criteria configured by the user. See here for more on this action can do.
    2. Style Actions: For more on this action including sample chains, see here.
    3. Search and replace: This action is based on calibre editor's search and replace. I included this mainly to be able to do search and replace on multiple books, leveraging the editor's function replace mode. More on this on the section on how to integrate the plugin with the action chains plugin.
    4. Mark cursor tag: Using this action you can mark tags, so that you can later apply batch operations on them using the Tag Actions. The way to do this, is the to make a chain containing the mark action and bind it to a keyboard shortcut. After that you can mark the tags by simply clicking on the shortcut when the cursor inside the tag.
      An example for using this can be found in this post.
    5. Add Templates: Add templates (css, images ... etc) to the ebook from predefined locations.
    6. Remove Files
    7. Remove Unused Images
    8. Flatten TOC
    9. Inline Styles To CSS: You can read more about this action here.
    10. Expand Styles
    11. Run command: Run a command of files inside the book.
  • Calibre editor builtin actions
    1. Create TOC.
    2. Insert Inline TOC.
    3. MultiSplit.
    4. Transform Styles.
    5. Transform HTML.
    6. Embed Fonts.
    7. Subset Fonts.
    8. Remove Unused CSS.
    9. Update Book Internals.
    10. Smarten Punctuation.
    11. Fix HTML.
    12. Beautify All.
    13. Compress Images.
    14. Arrange Into Folders.

How to use the plugin:

To make a new chain follow these steps:
  • From the drop-down menu choose the "Add/Modify chains" entry to open the config dialog.
  • In the config dialog press the add button to add a new empty chain.
  • Double click on the name field to give the new chain a name, and optionally choose a sub-menu and an icon.
  • To start adding actions to the chain, press the settings button in the chain row, which will open the add actions dialog.
  • In the add actions dialog, press on the add action button. After this choose and action you want from the actions combo-box. Press the action settings button configure the action.
  • Repeat for all actions you want to add, and then press OK.

Integration with Action Chains:
First, you must have the latest version of both the Editor Chains plugins and the Actions Chains plugin installed.

The combination of the two plugins will allow you to run your editor chains on multiple books in your library. You can do that be choosing to run whatever editor chain you want from Action Chains (which have action called "Run Editor Chain").

See here for more on how to use the Action Chains plugin.

Examples of how to use Tag Actions:
Below you can find links to two chains that you can import (Editor Chains > Add/Modify Chains > Right Click > Import Chain)
  • The first chain will match a range(s) of adjacent span tags that all share one similar class called "italic". This is an exact match, so it will not apply for spans containing other additional classes (although you can modify to do so if you want). And then, it merges all these spans into one span. You can download it from here.
  • The second chain goes one step further, by merging any adjacent spans with similar classes without having to specify what the classes are. You can download it from here.

Note: The criteria above makes sure there is no text between the spans that can break their continuity. But it still allows for text containing only white-space. You can refine this to include whatever punctuation characters you want, by modifying the regular expression in the text filters.

Running the plugin from the command line
You can run the plugin from the command line as follows:
Code:
calibre-debug -r "Editor Chains" chain_name input_file output_file
Note that before running the chain, it will be validated to make sure all member actions can be run from the command line. Currently, all actions in the plugin can run from the command line. Sometimes, However, a certain setting will make an action unavailable for the command line. e.g "Search and replace" with a setting to search "selected files", will not run from the command line (or from Action Chains plugin), because the setting needs the editor GUI to be open with files selected.


Note on Module Editor:
  • Similar to Action Chains plugin, this plugin provides a module editor for people who want to write their own actions. For information on how to write your own actions, see the comments in calibre_plugins.editor_chains.actions.base


Paypal Donations:
  • If you find this useful please feel free to show your appreciation.

Version History:
Spoiler:

Version 1.1.7 - 29 April 2024
Update: New Action: Download External Resources.
Fix: Scopes: epub3 toc file is not always called nav.xhtml. Make sure to lookup the name in the manifest without prior assumption.
Fix: Error when right clicking Actions Dialog. https://www.mobileread.com/forums/sh...4&postcount=89
Fix: replace "from calibre.gui2.widgets2 import Dialog" with "from calibre.gui2.tweak_book.widgets import Dialog" to fix dialogs not remembering sizes when calibre closes.
Misc changes to icon combobox.

Version 1.1.5 - 9 February 2024
Fix: some fixes for get_text()

Version 1.1.4 - 17 January 2024
Fix: Run Command: further problems when joining filename parts if directory is empty

Version 1.1.3 - 16 January 2024
Fix: Run Command: Don't join file components using os.path.join, because on Windows it uses backslashed and messes up the ebook filename.

Version 1.1.2 - 16 January 2024
Update: Run Command: Update media_type after running command.

Version 1.1.1 - 11 January 2024
Update: Modifications to "Run Command" action.
Fix: Actions Chains should not be installed for the plugin command line mode to work.

Version 1.1.0 - 8 January 2024
Update: Add "Arrange Into Folder" action.

Version 1.0.2 - 28 December 2023
Tag Actions: Search & Replace: Fix overlapping tags.

Version 1.0.1 - 15 December 2023
Tag Actions: Search & Replace: Some modifications.

Version 1.0.0 - 12 December 2023
Update: Add Templates: Action is rename into "Add Files". It now supports adding a directory tree into the book.
Update: Bump up config schema to 1.1

Version 0.9.6 - 4 December 2023
Fix: Bug in multisplit action.

Version 0.9.4 - 20 November 2023
Update: Action Chains: Add the ability to embed a chain instead of referencing and already existing chain.

Version 0.9.2 - 7 November 2023
Fix: Transform HTML: missing scope setting.

Version 0.9.1 - 15 September 2023
Update: Add another option to scopes to be able to select text file by performing a regex search on them.

Version 0.9.0 - 9 September 2023
Modifications to "Run Command" Action. Not backward compatible, so chains containing the action need to be recreated.

Version 0.8.9 - 29 August 2023
Update: New "Run Command" Action.
Update: Modifications to scopes.

Version 0.8.8 - 11 July 2023
Add API for imported actions and on_modules_update.

Version 0.8.7 - 22 May 2023
Fix: When running from Action Chains, notify calibre to update filesizes of modified files.

Version 0.8.6 - 15 May 2023
Update: Style Actions: New "Add Properties" Action.
Fix: Scopes: Enable (*.opf, *.ncx, *.txt, *.xml) files in both Include Filenames and Exclude Filenames.

Version 0.8.5 - 12 April 2023
Update: Add Templates Action: New options.

Version 0.8.4 - 9 April 2023
Fix: Bug when copying a separator.
Fix: Escape ampersands in menu entries.
Fix: Contamination of chain vars.

Version 0.8.3 - 19 December 2022
Update: New "Styles Actions" Actions.

Version 0.8.1 - 14 December 2022
Update: Add Templates: Add option to link added xhtml files to css sheets already in container.
Fix: Tag Actions: Style Property Filter: TypeError exception on comparison with None values.
Fix bug in Flatten TOC.

Version 0.8.0 - 11 December 2022
Update: Tag Actions: Add Style filter
Update: Tag Actions: Modifications to config widget.
Update: Tag Actions: Add ability to narrow down the nodes by css selectors.
Update: Tag Actions: set regex.DOTALL flag for "Tag Text" filter.
Fix: Tag Actions: Fix bug when specifying xpath and not configuring any tag filters.
Fix: Search & Replace: Replace function name not loading in config widget.
Fix: Expand Styles: Font size not updated in inline styles.
Fix: Tag Actions: regex values returning match object instead of True.

Version 0.7.2 - 5 December 2022
Update: Add "Expand Styles" Action.
Update: Add "Inline Styles To CSS" Action.
Update: Insert Inline TOC: Add option to insert TOC at tha back of the book.
Update: Insert Inline TOC: Add option to change the name of the inserted TOC.

Version 0.7.1 - 29 November 2022
Update: Add "Remove Files" Action.
Update: Add "Remove Unused Images" Action.
Update: Add "Insert Inline TOC" Action.
Update: Add "Flatten TOC" Action.
Update: Add "Transform HTML" Action.
Update: Add option to run suitable chains from command line using calibre-debug -r "Editor Chains" chain_name input_file output_file
Update: Multisplit: Add option to prevent splitting if no preceding sibling is found. Helpful in case or multiple runs, as it prevents creating empty pages.
Update: Tag Actions: New "Search And Replace" Action.
Update: Tag Actions: Add Xpath wizard to the context menu of the line edit.
Update: Modify behavior of xpath expressions in Tag Actions to include the element and its descendants (as opposed to descendants only).
Add validation for regex.
Fix: Search and Replace: Bug with multiple searches.

Version 0.7.0 - 28 November 2022
Update: Add some editor builtin actions.
Misc fixes.

Version 0.6.2 - 25 November 2022
Update: Don't add save point for chains invoked by chainer caller action.

Version 0.6.1 - 05 November 2022
Update: "Insert Before Cursor Tag" Action.
Update: "Insert After Cursor Tag" Action.
Update: Use regex module instead of re for consistency with calibre editor regex.

Version 0.6.0 - 25 October 2022
Update: Add "Run Python Code" Action.
Update: Add "Mark Cursor Tag".
Update: Add scope to some actions.
Misc fixes.

Version 0.5.4 - 9 August 2022
Update: update to calibre6 icon fetching. Code from @JimmXinu.
Fix: But where submenus where not working.

Version 0.5.3 - 17 July 2022
Fix PyQt6 migration bugs.

Version 0.5.2 - 29 June 2022
Fix: Export chain not working in PyQt6

Version 0.5.1 - 10 February 2022
Fix PyQt6 migration bug.

Version 0.5.0 - 6 January 2022
Changes for the upcoming PyQt6.

Version 0.4.1 - 8 November 2021
Misc updates.

Version 0.4.0 - 8 November 2021
Misc updates.

Version 0.3.1 - 6 November 2021
Misc updates.

Version 0.3.0 - 3 November 2021
Misc updates.

Version 0.2.0 - 30 October 2021
Fix toolbar action not updating.

Version 0.1.0 - 16 October 2021
Initial Release.

Attached Thumbnails
Click image for larger version

Name:	1.png
Views:	454
Size:	37.9 KB
ID:	198267   Click image for larger version

Name:	2.png
Views:	461
Size:	66.1 KB
ID:	198268   Click image for larger version

Name:	3.png
Views:	434
Size:	65.6 KB
ID:	198269   Click image for larger version

Name:	4.png
Views:	387
Size:	72.4 KB
ID:	198270   Click image for larger version

Name:	5.png
Views:	350
Size:	21.5 KB
ID:	198271   Click image for larger version

Name:	7.png
Views:	360
Size:	30.2 KB
ID:	198272   Click image for larger version

Name:	8.png
Views:	335
Size:	39.9 KB
ID:	198273   Click image for larger version

Name:	9.png
Views:	313
Size:	53.0 KB
ID:	198274   Click image for larger version

Name:	10.png
Views:	354
Size:	159.8 KB
ID:	198275  
Attached Files
File Type: zip Editor Chains_1.1.7.zip (688.5 KB, 1179 views)

Last edited by capink; 04-29-2024 at 11:44 AM. Reason: version 1.1.7
capink is offline   Reply With Quote