View Single Post
Old 09-20-2016, 08:45 PM   #9
nabsltd
Fanatic
nabsltd ought to be getting tired of karma fortunes by now.nabsltd ought to be getting tired of karma fortunes by now.nabsltd ought to be getting tired of karma fortunes by now.nabsltd ought to be getting tired of karma fortunes by now.nabsltd ought to be getting tired of karma fortunes by now.nabsltd ought to be getting tired of karma fortunes by now.nabsltd ought to be getting tired of karma fortunes by now.nabsltd ought to be getting tired of karma fortunes by now.nabsltd ought to be getting tired of karma fortunes by now.nabsltd ought to be getting tired of karma fortunes by now.nabsltd ought to be getting tired of karma fortunes by now.
 
Posts: 521
Karma: 8500000
Join Date: Aug 2013
Location: Hamden, CT
Device: Kindle Paperwhite (11th gen), Scribe, Kindle 4 Touch
Quote:
Originally Posted by DiapDealer View Post
First off: you're right. Regex is not the best tool for removing tags based on attribute values. But I don't think that's what the OP was asking for (nor what Toxaris was suggesting using regex for). The OP is asking for something that removes classes (classes that are no longer being used by CSS) from attribute strings.
I didn't get that from the post, as he was asking to delete unused stuff from the HTML file. If you just want to delete an attribute on an HTML element, then it's not too hard (although you have to account for things like
Code:
class="first second"
That might leave you with a span that does nothing effective, but if it has other attributes, it won't be deleted as "empty" by the various tools. In other words, I couldn't figure out how he ended up with attributes that do nothing so they can be deleted safely, so I assumed he meant deleting the span/div/etc.

Quote:
By the way: both the TagMechanic plugin for Sigil, and "Diap's Editing Toolbag" for calibre make it trivial to successfully remove the tag with the class "deleteme" (along with the matching closing tag), per your example.
Definitely a good start, but I'm spoiled by Expression Web and the selection process it has for elements to modify (with/without attribute, containing/not containing text/tag, inside/not inside tag, with infinite nesting of these rules) plus what it can do (replace tag/contents, add before/after start/end tag, remove tag/contents, change tag, change/remove attribute), and all of it can be regexed.
nabsltd is offline   Reply With Quote