encodeBackslashEscapes.js 962 B

123456789101112131415161718192021
  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('makehtml.encodeBackslashEscapes', function (text, options, globals) {
  13. 'use strict';
  14. text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.before', text, options, globals).getText();
  15. text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
  16. text = text.replace(/\\([`*_{}\[\]()>#+.!~=|:-])/g, showdown.helper.escapeCharactersCallback);
  17. text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.after', text, options, globals).getText();
  18. return text;
  19. });