mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
(new) support for unquoted data URIs in url()
This commit is contained in:
@@ -530,13 +530,28 @@ less.Parser = function Parser(env) {
|
||||
var value;
|
||||
|
||||
if (input.charAt(i) !== 'u' || !$(/^url\(/)) return;
|
||||
value = $(this.entities.quoted) || $(this.entities.variable) || $(/^[-\w%@$\/.&=:;#+?]+/) || "";
|
||||
value = $(this.entities.quoted) || $(this.entities.variable) ||
|
||||
$(this.entities.dataURI) || $(/^[-\w%@$\/.&=:;#+?]+/) || "";
|
||||
if (! $(')')) throw new(Error)("missing closing ) for url()");
|
||||
|
||||
return new(tree.URL)((value.value || value instanceof tree.Variable)
|
||||
return new(tree.URL)((value.value || value.data || value instanceof tree.Variable)
|
||||
? value : new(tree.Anonymous)(value), imports.paths);
|
||||
},
|
||||
|
||||
dataURI: function () {
|
||||
var obj;
|
||||
|
||||
if ($(/^data:/)) {
|
||||
obj = {};
|
||||
obj.mime = $(/^[^\/]+\/[^,;)]+/) || '';
|
||||
obj.charset = $(/^;\s*charset=[^,;)]+/) || '';
|
||||
obj.base64 = $(/^;\s*base64/) || '';
|
||||
obj.data = $(/^,\s*[^)]+/);
|
||||
|
||||
if (obj.data) { return obj }
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// A Variable entity, such as `@fink`, in
|
||||
//
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.URL = function (val, paths) {
|
||||
// Add the base path if the URL is relative and we are in the browser
|
||||
if (!/^(?:https?:\/|file:\/)?\//.test(val.value) && paths.length > 0 && typeof(window) !== 'undefined') {
|
||||
val.value = paths[0] + (val.value.charAt(0) === '/' ? val.value.slice(1) : val.value);
|
||||
if (val.data) {
|
||||
this.attrs = val;
|
||||
} else {
|
||||
// Add the base path if the URL is relative and we are in the browser
|
||||
if (!/^(?:https?:\/|file:\/)?\//.test(val.value) && paths.length > 0 && typeof(window) !== 'undefined') {
|
||||
val.value = paths[0] + (val.value.charAt(0) === '/' ? val.value.slice(1) : val.value);
|
||||
}
|
||||
this.value = val;
|
||||
this.paths = paths;
|
||||
}
|
||||
this.value = val;
|
||||
this.paths = paths;
|
||||
};
|
||||
tree.URL.prototype = {
|
||||
toCSS: function () {
|
||||
return "url(" + this.value.toCSS() + ")";
|
||||
return "url(" + (this.attrs ? 'data:' + this.attrs.mime + this.attrs.charset + this.attrs.base64 + this.attrs.data
|
||||
: this.value.toCSS()) + ")";
|
||||
},
|
||||
eval: function (ctx) {
|
||||
return new(tree.URL)(this.value.eval(ctx), this.paths);
|
||||
return this.attrs ? this : new(tree.URL)(this.value.eval(ctx), this.paths);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -72,3 +72,10 @@ p + h1 {
|
||||
width: 100%!important;
|
||||
height: 20px ! important;
|
||||
}
|
||||
#data-uri {
|
||||
background: url(data:image/png;charset=utf-8;base64,
|
||||
kiVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/
|
||||
k//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U
|
||||
kg9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC);
|
||||
background-image: url(data:image/x-png,f9difSSFIIGFIFJD1f982FSDKAA9==);
|
||||
}
|
||||
|
||||
@@ -86,3 +86,10 @@ p + h1 {
|
||||
height: 20px ! important;
|
||||
}
|
||||
|
||||
#data-uri {
|
||||
background: url(data:image/png;charset=utf-8;base64,
|
||||
kiVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/
|
||||
k//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U
|
||||
kg9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC);
|
||||
background-image: url(data:image/x-png,f9difSSFIIGFIFJD1f982FSDKAA9==);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user