|
|
#1 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 324
Karma: 50000
Join Date: May 2014
Device: Kobo Libra 2
|
Using Editor to mass delete anything contained in a Class?
I used the FanFicFare plugin to download a work from RoyalRoad. Near the beginning and/or the end of most of the chapters is an author's note, which I'd like to remove. There are over 600 chapters, I don't want to do it manually.
Each of these notes is within a section marked as follows: < div class="portlet" > Which seems like it would be easy to clear, but there are more < div > within the note, so I can't just regex with < /div > as the endpoint of the find. Any thoughts on how to handle this? Full code chunk with plaintext changed: Code:
<div class="calibre1"><div class="portlet">
<div class="calibre1">
<div class="calibre1">
<span class="calibre2">A note from Author</span>
</div>
</div>
<div class="calibre1"><p class="calibre4"><span>I want to thank all of my patrons, including:</span></p>
<p class="calibre4"><span>Person</span></p>
<p class="calibre4"><span>Person</span></p>
<p class="calibre4"><span>Person</span></p>
<p class="calibre4"><span>And my 2 other patrons!</span></p>
<p class="calibre4"></p>
<p class="calibre4"><span>Thank you!</span></p>
<p class="calibre4"></p>
</div>
</div>
|
|
|
|
|
|
#2 |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,918
Karma: 64187770
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Use the following Calibre (editor) Plugin
https://www.mobileread.com/forums/sh....php?p=2980740 It accepts arguments on which to apply |
|
|
|
|
|
#3 | |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 324
Karma: 50000
Join Date: May 2014
Device: Kobo Libra 2
|
Quote:
|
|
|
|
|
|
|
#4 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,891
Karma: 9600930
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
|
This will take a few separate regex's to accomplish.
First you need to "Fix HTML - All files" and then "Beautify all files" which are tools in the editor. The spacing, tabs and layout look a mess. You need to get consistency across all the tags. You also need to check that the classes being used in the tags are unique to these Authors Notes otherwise you will also be removing parts of the book you want to keep. Then you need to step through the regexes. Remember to also capture the tabs and line before so you don;t end up with lot's of spacing. Start with removing the empty <p class="calibre4"></p> tags. Then remove the <p class="calibre4"><span>(.*?)</span></p> tags. Then remove the <div> tags using Edit Spans & Divs, which I think is part of Diap's Toolbag plugin. Then run the "Fix HTML - All files" and then "Beautify all files" again to remove all the extra line feeds. |
|
|
|
|
|
#5 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 324
Karma: 50000
Join Date: May 2014
Device: Kobo Libra 2
|
Thanks for this very clear writeup!
Unfortunately, as I dug further into the edits, things keep changing in the layout, and sometimes the classes are reused for things that need to be kept. But I've learned a lot today, and it will be useful for future edits. |
|
|
|
|
|
#6 |
|
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 84,438
Karma: 153744815
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
It sounds like a manual edit of all 600 chapters is in order.
|
|
|
|
|
|
#7 |
|
Not Quite Dead
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 196
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Is the .portlet class reused? If not, you can skip working with the html and use the stylesheet:
div.portlet {display: none;} |
|
|
|
|
|
#8 | |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,891
Karma: 9600930
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
|
Quote:
Maybe you could be strict on the spacing. Something like... \s{6,12}<p class="calibre4"><span> The numbers in the brackets are min,max spaces to search for. Without seeing the book, maybe the authors note, with multiple div wrappings, might bump the spacing more than what is used in the rest of the book. |
|
|
|
|
|
|
#9 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 46,434
Karma: 29634066
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Just FYI the correct tool to use for this is the Transform HTML tool which is under Tools->Transform markup
in it you can create a rule like if the tag has class whatever, remove it. |
|
|
|
|
|
#10 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,891
Karma: 9600930
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
|
If the same class is being used in the block to be removed, as well as in areas not to be removed, how do you ensure with the Transform tool that you do not remove the wrong elements?
|
|
|
|
|
|
#11 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 46,434
Karma: 29634066
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
depends on what information is present to discriminate between the scenarios in the first place. My point was more that for the task of editing HTML rather than relying on regex which is fragile use the transform html tool.
|
|
|
|
|
|
#12 | |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 324
Karma: 50000
Join Date: May 2014
Device: Kobo Libra 2
|
Quote:
Code:
If the tag has class portlet Remove tag and children |
|
|
|
|
|
|
#13 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 324
Karma: 50000
Join Date: May 2014
Device: Kobo Libra 2
|
In my case, it was some classes like calibre4 and calibre2 that became other things in other chapters. The 'portlet' tag was consistent.
|
|
|
|
|
|
#14 | |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,365
Karma: 1589505
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
|
Quote:
Choose 'Regex' mode and 'All text files'. Remember to check the 'Wrap' and 'Dot all' options. Code:
<div class="portlet">.*?<p class="calibre4"><span>Thank you!</span></p>.*?</div> Edit: Nevermind. I didn't notice you already solved the problem. Last edited by thiago.eec; 08-07-2026 at 11:09 AM. |
|
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Mass delete of .mobi files | lynncal | Calibre | 6 | 03-17-2024 08:53 PM |
| Recovery from aborted Mass Delete | PickleBucket90 | Library Management | 3 | 11-10-2021 09:06 PM |
| How can I mass delete books from a Kindle? | MisterSnrub | Amazon Kindle | 3 | 11-24-2019 08:58 AM |
| Mass delete of unpopular tags | jacr | Library Management | 25 | 07-21-2018 10:43 PM |
| A way to mass delete Ids? | raithe | Library Management | 9 | 10-22-2015 06:36 AM |