diff --git a/lib/less/functions.js b/lib/less/functions.js index fbde54ff..9968c59d 100644 --- a/lib/less/functions.js +++ b/lib/less/functions.js @@ -213,6 +213,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")); }, + gsub: function (str, regexp, replacement) { + var str = str.value; + + str = str.replace(new RegExp(regexp.value, "g"), replacement.value); + + return new(tree.Quoted)('"' + str + '"', str) + }, '%': function (quoted /* arg, arg, ...*/) { var args = Array.prototype.slice.call(arguments, 1), str = quoted.value; diff --git a/test/css/functions.css b/test/css/functions.css index eacebd8d..499b614c 100644 --- a/test/css/functions.css +++ b/test/css/functions.css @@ -8,6 +8,7 @@ } #built-in { escaped: -Some::weird(#thing, y); + gsub: "Hello, World!"; lighten: #ffcccc; darken: #330000; saturate: #203c31; diff --git a/test/less/functions.less b/test/less/functions.less index f60dab47..d84ae6bd 100644 --- a/test/less/functions.less +++ b/test/less/functions.less @@ -12,6 +12,7 @@ #built-in { @r: 32; escaped: e("-Some::weird(#thing, y)"); + gsub: gsub("Hello, Foo.", "Foo\.$", "World!"); lighten: lighten(#ff0000, 40%); darken: darken(#ff0000, 40%); saturate: saturate(#29332f, 20%);