cssutils icon indicating copy to clipboard operation
cssutils copied to clipboard

getUrls method for single CSSRule, not CSSStyleSheet?

Open vdmit opened this issue 4 years ago • 1 comments

currently getUrls method could be applied to CSSStyleSheet object only. Is there a simple way to get urls from single CSS rule? My workaround is like following:

from cssutils import CSSParser
from cssutils.css import CSSStyleRule
from cssutils.css import CSSStyleSheet
from cssutils import getUrls

parser = CSSParser()
style = parser.parseStyle(cssText="height:450px; background-image: url('https://example.com/image.png');")

rule = CSSStyleRule(selectorText="html", style=style)

css = CSSStyleSheet()
css.add(rule)
print(list(getUrls(css)))

but it seems to be a bit over-engineered. Is there a better/faster way?

vdmit avatar Aug 12 '21 16:08 vdmit

I'm not particularly familiar with the implementation, so I don't have a good answer to your question. I hope someone else does or maybe you can dive into the code and find your own answer. I'd be happy to consider patches that would make the usage easier.

jaraco avatar Jun 03 '22 02:06 jaraco