encodeBackslashEscapes.js 703 B

1234567891011121314151617
  1. /**
  2. * Returns the string, with after processing the following backslash escape sequences.
  3. *
  4. * attacklab: The polite way to do this is with the new escapeCharacters() function:
  5. *
  6. * text = escapeCharacters(text,"\\",true);
  7. * text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);
  8. *
  9. * ...but we're sidestepping its use of the (slow) RegExp constructor
  10. * as an optimization for Firefox. This function gets called a LOT.
  11. */
  12. showdown.subParser('encodeBackslashEscapes', function (text) {
  13. 'use strict';
  14. text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
  15. text = text.replace(/\\([`*_{}\[\]()>#+-.!~])/g, showdown.helper.escapeCharactersCallback);
  16. return text;
  17. });