View Single Post
Old 05-09-2022, 05:47 PM   #90
tamaracks
Connoisseur
tamaracks began at the beginning.
 
tamaracks's Avatar
 
Posts: 53
Karma: 10
Join Date: Jun 2021
Device: Onyx Boox Nova3
Quote:
Originally Posted by KevinH View Post
Its a bug in cutils2.py in the removeBadAttributesfromCSS(wdir, file) routine.
Thanks for tracking down the location! I tried to look up what pseudo selectors/elements would be valid, but I'm not sure if I know where to find the right answer at the moment. And also, even if there's a pseudo-selector that isn't approved for EPUB, a simple exception list doesn't cover it, because you *still* wouldn't want to break up the colons, I think. Because you're just making it less valid.

I took a different tack and rewrote that whole if statement to only make a change if a : and ; are detected in the line. Which I think should help in most cases. I'm sure there's a flaw there too, if this code is covering both HTML and CSS files, but I think it errs on the side of not changing a thing instead of breaking it. I'm not entirely sure what this part of the code is intended to fix, to be honest. Just to make it look more readable/uniform? If that's the case, it's not taking into account the ' : ' I just saw in one book's CSS, so it's incomplete anyway. Which is fine, it just makes me not feel bad about my change being incomplete, haha.

I think you're right that using a css parser would be the way to go, but my python skills are quite nascent, so I don't have the time to work it out. However I've noticed that Sigil has a 'ReformatCSSMultipleLines' command in Automate Lists that seems to do a pretty decent job. Interestingly, I can only find it in Automate lists, not as a menu command somewhere else, unless I'm missing something. Can a plugin call those commands?

For now, this is what I ended up with for that section of code:
Code:
            else:
                if ':' in line and ';' in line:
                    if ': ' in line:
                        pass
                    else:
                        line = line.replace(':', ': ')
                else:
                    pass    
                outfp.write(line)
tamaracks is offline   Reply With Quote