Last active
January 9, 2017 11:08
-
-
Save agoalofalife/23ae5bd50ed188b0d8c82348ae010968 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// для escape значений | |
function escapeHtml (string) { | |
return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) { | |
return entityMap[s]; | |
}); | |
} | |
var entityMap = { | |
'&': '&', | |
'<': '<', | |
'>': '>', | |
'"': '"', | |
"'": ''', | |
'/': '/', | |
'`': '`', | |
'=': '=' | |
}; | |
// карта для escape | |
compileTags(tags || mustache.tags); // mustache.tags = [ '{{', '}}' ]; | |
// для преобразований регулярных выражений | |
function escapeRegExp (string) { | |
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&'); | |
} | |
openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + '\\s*'); // регулярка на открытй тег | |
closingTagRe = new RegExp('\\s*' + escapeRegExp(tagsToCompile[1])); // регулярка на закрытый тег тег | |
closingCurlyRe = new RegExp('\\s*' + escapeRegExp('}' + tagsToCompile[1])); | |
// обрезать все {{ }} и получить текущие куски между ними |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment