Skip to content

Instantly share code, notes, and snippets.

@clee704
Created May 14, 2013 00:41
Show Gist options
  • Save clee704/5572740 to your computer and use it in GitHub Desktop.
Save clee704/5572740 to your computer and use it in GitHub Desktop.
Convert CSS URI values
# Parse CSS URI values according to http://www.w3.org/TR/CSS21/syndata.html#uri
URI_PATTERN = /
url\( # 'url('
[ \t\n\r\f]* # optional white space
(
# double quoted URI
(
(?<quote>") # an optional double quote
(?<str>([^"\\]|\\.)*?) # URI
"
)
# or single quoted
| (
(?<quote>') # an optional single quote
(?<str>([^'\\]|\\.)*?) # URI
'
)
# or unquoted
| (?<str>
([^() \t\n\r\f'"\\]|\\.)* # parentheses, white space characters,
# single quotes, and double quotes must be
# escaped
)
)
[ \t\n\r\f]* # optional white space
\) # ')'
/x
data = 'load css file here'
data.gsub! URI_PATTERN do |match|
# TODO do something here
puts $~[:quote], $~[:str]
'url([PUT SOMETHING HERE])'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment