![]() |
"Delete unused stylesheet classes" problems with overloaded styles
I was looking at an ePub with these styles:
(passes ePubCheck , no warnings). Code:
.width-auto-rw .pc-rw { width: auto; }Code:
<div class="width-10-rw">I run "Delete unused stylesheet classes" and the styles are reduced to Code:
.width-auto-rw .pc-rw { width: auto; }The display of the image using the code above is now messed up, as it is not constrained by "width: 100%;". It's very confusing to me all the definitions of "pc-rw" and it seems it also confused "Delete unused stylesheet classes". I understand that .a, .b, .c {margin: 0;} means three identical styles. And table.a {color: red;} p.a {color:blue;} makes two different styles, one for each of the base styles named. But what does omitting the comma do? Also, after doing the "Remove", the display in Sigil was unchanged. I opened a few chapters to check and they all looked unchanged, so I felt safe to commit and saved the file. Then the image size went whacky. Fortunately I had a backup of the file to restore the missing styles and try to work out what had gone wrong. I know that the CSS is bizarre, but it is valid. Trying to simplify it is why I start with "Remove". |
Does the css pass w3c validation before "Delete unused..."? Epubcheck does not validate css to my knowledge.
|
Try changing the ".pc-rw img" to "div.pc-rw img", or add it with the same css and see if that works. Not that I've seen a lot of css but I've never seen a descendant selector where the parent is a bare css class; I thought there had to be an html tag, with or without a class.
|
Quote:
|
Quote:
Code:
div p img { ... }Code:
div > p > img { ... } |
Quote:
Quote:
"ERROR(CSS-008): An error occurred while parsing the CSS: Token '{' not allowed here, expecting :." It did not complain about the original file. |
Found another file:
Code:
<div class="chapter"> |
We'll look into it. Thanks for reporting the issue and providing examples.
@jswolf: please do us a favor and stay out of the trouble-shooting process. What should/shouldn't be necessary is not at all helpful when debugging a potential issue. Only steps to reproduce the potential issue, and steps to try and work around the potential issue are helpful. Extra noise is only a distraction. |
Quote:
Code:
<p class="pc-rw">Code:
<p class="pc-rw"> |
Yes. Again ... we're aware of how css works. At this point, suggestions are being made to see if it they have any affect on what the "Delete Unused Stylesheet Classes" feature of Sigil removes. Please, everyone, refrain from turning this thread into a CSS course.
|
Also keep in mind that any automated process's ability to accurately determine whether a css class is "in use" will never be 100%.
|
Hi, since I didn't want to reappear just to point out that the plugin cssRemoveUnusedSelectors can be used to overcome some limitations of the builtin Delete Unused Stylesheet Classes, I took a peek at the Sigil source code to look for the culprit of this behavior.
If I correctly understood the code, Sigil in BookReports::AllClassesUsedInHTMLFileMapped retrieves all the couples tagname - classname used in xhtml files, and then look for a match with every css selector that happens to contain at least one .dot-preceded-classname (CSSInfo::getAllCSSSelectorsForElementClass). If the selector doesn't contain tagnames, it will match if it contains the appropriate classname, otherwise it will have to contain the appropriate sequence tagname.classname for the match to happen. This is problematic for compound selectors, since they can contain tagnames and classnames which don't refer to the same element: so, if a user have a selector like ".chapter p" it will probably never match anything, and I'm afraid it won't be easy to amend the code (at least, it wouldn't be easy if it was me that had to work on it...). A selector like "div.chapter p" will instead match if there is a div element in xhtml with the class chapter, even if it hasn't any p descendant - which can be good, I guess. Pseudo classes and pseudo elements, like :first-of-type and ::first-line, seems to me that they aren't handled in any way in CSSInfo, so I suppose that they become part of the classname or the tagname that precedes them. In fact, if you have Code:
<p class="matchthis:first-of-type">Code:
p.matchthis:first-of-type {}(There is also the possibility that I misunderstood all the Sigil's source code and the answers are totally different. New year will tell... Cheers! :beer:) |
Long on my todo list is to add a real C or C++ library css parser but I have not found one that I like. If I do I will add it. Until we do, we have to live with the Sigil css parser which was designed in css2 epub2 days and unfortunately not my code at all so I am not 100% sure I am following it.
So the best we can offer in the case of compound tags is to split them internally and then assume any more complex structure is to be left alone, ie, not offered up as an unused selector of any sort. I will look into it. |
Quote:
|
Quote:
I switched to using the plugin since it seemed to work better with some overly complex stylesheets. |
| All times are GMT -4. The time now is 10:18 PM. |
Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.