mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 00:57:48 +00:00
Merging in escaping for Underscore templates, using <%- syntax. Sorry Eco.
This commit is contained in:
@@ -816,7 +816,7 @@
|
||||
for (var i = 0; i < n; i++) iterator.call(context, i);
|
||||
};
|
||||
|
||||
// Escape string for HTML
|
||||
// Escape a string for HTML interpolation.
|
||||
_.escape = function(string) {
|
||||
return (''+string).replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/');
|
||||
};
|
||||
@@ -842,7 +842,7 @@
|
||||
_.templateSettings = {
|
||||
evaluate : /<%([\s\S]+?)%>/g,
|
||||
interpolate : /<%=([\s\S]+?)%>/g,
|
||||
encode : /<%==([\s\S]+?)%>/g
|
||||
escape : /<%-([\s\S]+?)%>/g
|
||||
};
|
||||
|
||||
// JavaScript micro-templating, similar to John Resig's implementation.
|
||||
@@ -854,7 +854,7 @@
|
||||
'with(obj||{}){__p.push(\'' +
|
||||
str.replace(/\\/g, '\\\\')
|
||||
.replace(/'/g, "\\'")
|
||||
.replace(c.encode, function(match, code) {
|
||||
.replace(c.escape, function(match, code) {
|
||||
return "',_.escape(" + code.replace(/\\'/g, "'") + "),'";
|
||||
})
|
||||
.replace(c.interpolate, function(match, code) {
|
||||
|
||||
Reference in New Issue
Block a user