MCPcopy Create free account
hub / github.com/TruthHun/BookStack / createEscaper

Function createEscaper

static/word2md/mammoth.browser.js:29203–29215  ·  view source on GitHub ↗
(map)

Source from the content-addressed store, hash-verified

29201
29202 // Functions for escaping and unescaping strings to/from HTML interpolation.
29203 var createEscaper = function(map) {
29204 var escaper = function(match) {
29205 return map[match];
29206 };
29207 // Regexes for identifying a key that needs to be escaped
29208 var source = '(?:' + _.keys(map).join('|') + ')';
29209 var testRegexp = RegExp(source);
29210 var replaceRegexp = RegExp(source, 'g');
29211 return function(string) {
29212 string = string == null ? '' : '' + string;
29213 return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
29214 };
29215 };
29216 _.escape = createEscaper(escapeMap);
29217 _.unescape = createEscaper(unescapeMap);
29218

Callers 1

mammoth.browser.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected