Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/less/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ tree.functions = {
escape: function (str) {
return new(tree.Anonymous)(encodeURI(str.value).replace(/=/g, "%3D").replace(/:/g, "%3A").replace(/#/g, "%23").replace(/;/g, "%3B").replace(/\(/g, "%28").replace(/\)/g, "%29"));
},
replace: function (subject, pattern, replacement, flags) {
var str = subject.value;

str = str.replace(new RegExp(pattern.value, flags ? flags.value : ""), replacement.value);

return new(tree.Quoted)('"' + str + '"', str);
},
'%': function (quoted /* arg, arg, ...*/) {
var args = Array.prototype.slice.call(arguments, 1),
str = quoted.value;
Expand Down
3 changes: 3 additions & 0 deletions test/css/functions.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
contrast-dark-thresh-per: #eeeeee;
contrast-high-thresh-per: #eeeeee;
contrast-low-thresh-per: #111111;
replace: "Hello, World!";
replace-captured: "This is a new string.";
replace-with-flags: "2 + 2 = 4";
format: "rgb(32, 128, 64)";
format-string: "hello world";
format-multiple: "hello earth 2";
Expand Down
3 changes: 3 additions & 0 deletions test/less/functions.less
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
contrast-dark-thresh-per: contrast(#000, #111111, #eeeeee, 50%);
contrast-high-thresh-per: contrast(#555, #111111, #eeeeee, 60%);
contrast-low-thresh-per: contrast(#555, #111111, #eeeeee, 10%);
replace: replace("Hello, Mars.", "Mars\.", "World!");
replace-captured: replace("This is a string.", "(string)\.$", "new $1.");
replace-with-flags: replace("One + one = 4", "one", "2", "gi");
format: %("rgb(%d, %d, %d)", @r, 128, 64);
format-string: %("hello %s", "world");
format-multiple: %("hello %s %d", "earth", 2);
Expand Down