08-28-2018, 10:50 AM | #1 |
Enthusiast
Posts: 25
Karma: 10
Join Date: Mar 2014
Device: Pocket Book Touch Lux 4
|
Batch-Processing of CSS in epub
Hi there
I often have to work over a whole series of calibre-created epubs where I do the same corrections in the CSS over and over... Now I want to ask if there is any way to do this in a batch or something similar? Much thanks in advance for your help! |
08-28-2018, 12:52 PM | #2 |
Sigil Developer
Posts: 8,263
Karma: 5568412
Join Date: Nov 2009
Device: many
|
That all depends on what you are trying to do exactly. Both Sigil and Calibre allow regular expression based search and replace which can be used to automate the tasks. Both Sigil and Calibre allow plugins that can auto process any loaded epub. But creating a Sigil or Calibre plugin requires some knowledge of python and some knowledge of the plugin interface mechanism. Sigil's is perhaps easier to learn by example and is limited to the contents of the ebook, whereas Calibre's plugins have a more complicated interface but can do more.
That said, if you know some python or how to use regular expressions (or .bat files and have a tool you use) and your books are all epubs, you should be able to write a script to open (unzip) each epub in a folder, process it as desired, re zip up the revised epub, and repeat. So it is hard to help without some idea of the changes needed in detail. |
Advert | |
|
08-28-2018, 01:01 PM | #3 |
Grand Sorcerer
Posts: 28,100
Karma: 201052868
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
I was looking at ways to add an "All CSS Files" option to our F&R parameters, but my head very quickly spun when trying to grasp the logic of that code.
The only way to currently do regex processing on css files is one file at a time with "Current File" selected. I think many would like an "All CSS Files option." But from what I saw, it looked like adding that option would require a minor overhaul of the existing F&R codebase. But even that's not going to help the OP "batch process" css from many individual epubs. Sigil is really not geared toward batch processing at all. |
08-28-2018, 02:47 PM | #4 |
Klak
Posts: 174
Karma: 150374
Join Date: Sep 2011
Location: Belgrade, Serbia
Device: many
|
i open css with notepad++ and run multiple regex search&replace with notepad++ python script plugin.
for sure it can be done with sigils plugin engine but i am used to do it this way. notepad++ python script plugin comes with couple sample plugins. edit: it is just one epub with multiple changes. i don't know how to do the same thing on multiple epubs Last edited by najgori; 08-28-2018 at 03:29 PM. |
08-29-2018, 10:16 AM | #5 | |
Imperfect Perfectionist
Posts: 576
Karma: 863576
Join Date: Dec 2011
Location: Ølstykke, Denmark
Device: none
|
Quote:
The only tool I know of that's able to do that (in Windows anyway), is PowerGrep https://www.powergrep.com/, but it comes with both a learning curve and a price tag, and both sort of steep … I'm told that there exists a Linux commandline grep-tool to search and (maybe?) replace in zip files - zipgrep. I've not used Linux lately, but you might be able to use it in a shell script or something. As allways: FWIW. Regards, Kim |
|
Advert | |
|
08-29-2018, 12:06 PM | #6 |
creator of calibre
Posts: 44,737
Karma: 24967300
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Use the transform styles tool in the calibre conversion dialog -- it allows you to create rules to manipulate CSS and can work in bulk. The tool is also present int he calibre editor, but that works one book at a time.
Last edited by kovidgoyal; 08-29-2018 at 10:58 PM. |
08-29-2018, 08:32 PM | #7 |
A Hairy Wizard
Posts: 3,248
Karma: 19222221
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
You can also just use a template css file that has all of your standard css that you want.
Then just use whatever form of search & replace, powergrep, etc. to change the tags within the html documents to match what you already have in the css. |
08-31-2018, 11:44 AM | #8 |
Guru
Posts: 681
Karma: 929286
Join Date: Apr 2014
Device: PW-3, iPad, Android phone
|
Since epubs are zip files, use a command line unzipper to unzip all to a folder.
Now you can use whatever S&R app or text editor you like that has a batch mode to edit the css and xhtml of all the files of interest at once. Even sed, perl, whatever. Rezip-- I know that you need to zip without compressing the mimetype file, there are ways to do that, e.g. epubpack. Last edited by AlanHK; 08-31-2018 at 12:19 PM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Batch processing with kindlegen | Blunaigel | Kindle Formats | 28 | 01-25-2019 11:01 AM |
Is there a way to batch edit multiple epub css? | stevenam | ePub | 10 | 12-30-2016 04:40 AM |
In an ePub reader, what are the rules for processing styles/CSS? | mattcurtis | ePub | 1 | 04-05-2013 12:11 PM |
Tag editor with batch processing | semenoof | General Discussions | 0 | 01-17-2013 04:12 AM |
Batch processing of PDB files? | Asterra | iRex | 6 | 12-04-2007 02:10 PM |