utilities#
A few utility functions which may help when working with CSS stylesheets.
getUrls
#
- cssutils.getUrls(sheet)#
Retrieve all
url(urlstring)
values (in e.g.cssutils.css.CSSImportRule
orcssutils.css.CSSValue
objects of given sheet.- Parameters:
sheet –
cssutils.css.CSSStyleSheet
object whose URLs are yielded
This function is a generator. The generated URL values exclude
url(
and)
and surrounding single or double quotes.
replaceUrls
#
- cssutils.replaceUrls(sheet, replacer, ignoreImportRules=False)#
- cssutils.replaceUrls(style: CSSStyleDeclaration, replacer, ignoreImportRules=False)
Replace all URLs in
cssutils.css.CSSImportRule
orcssutils.css.CSSValue
objects of given sheet.- Parameters:
sheet – a
cssutils.css.CSSStyleSheet
to be modified in place.replacer – a function which is called with a single argument url which is the current value of each url() excluding
url(
,)
and surrounding (single or double) quotes.ignoreImportRules – if
True
does not call replacer with URLs from @import rules.
resolveImports
#
- cssutils.resolveImports(sheet, target=None)#
Recursively combine all rules in given sheet into a target sheet. Attempts to wrap @import rules that use media information into @media rules, keeping the media information. This approach may not work in all instances (e.g. if an @import rule itself contains an @import rule with different media infos or if it contains rules that may not be used inside an @media block like @namespace rules). In these cases, the @import rule from the original sheet takes precedence and a WARNING is issued.
- Parameters:
sheet –
cssutils.css.CSSStyleSheet
from which all import rules are resolved and added to a resulting flat sheet.target – A
cssutils.css.CSSStyleSheet
object that will be the resulting flat sheet if given.
- Returns:
cssutils.css.CSSStyleSheet
with imports resolved.