Precedence of stylesheets
Pure Java HTML / CSS rendering engine
Status: Beta
Brought to you by:
radkovo
When multiple stylesheets are passed to this constructor:
public DirectAnalyzer(List<StyleSheet> sheets)
The precedence of stylesheets doesn't appear to be respected.
For example, if I pass two stylesheets:
#target { background : red }
and
#target { background : green }
in that order, then the background of #target
should be green, but it is being computed as red.
I am using the latest version of jStyleParser (1.19)
Anonymous
The rendering in SF.net has a bug if a line begins with
#
, and I can't edit the previous post. Hence, posting again.The first stylesheet:
The second stylesheet:
Hi,
I am unable to reproduce the buggy behavior. Do you have any test case? My testing code is the following (based on some of your previous tests :-)
In the above testing code, you are concatenating the two rules inside a single stylesheet.
Can you try creating two different stylesheets (two different
<style>
elements)?Oops, never mind! The
<style>
element is not being actually used in the above code. I will try to create a test case.There seems to be some race condition involved here. Not sure if it is in our code or jStyleParser. Will investigate and confirm later.
Thanks again for your quick responses!
I was able to reproduce the problem and also trace the root cause.
The priority of every ruleset is being set during parsing stage. And the rules are sorted based on this priority in DirectAnalyser.getDeclarationsForElement().
Now, in our application, the order of parsing is not necessarily the same as the document order. This was causing the problem in our case.
As a workaround, there are two changes I did:
1. Used a LinkedHashSet instead of a HashSet to store candidates in
getDeclarationsForElement()
. This preserves the order of the rulesets and yet removes duplicates.2. Implemented a new priority strategy that simply returns a zero priority everytime.
With these changes, I am seeing perfect behavior.
The first change is simple. For the second change, it would be good if the priority strategy was configurable. If you are okay, I will make a PR for it.
Solved on GitHub.
Closed in 1.20