encodeCode.js 753 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * Encode/escape certain characters inside Markdown code runs.
  3. * The point is that in code, these characters are literals,
  4. * and lose their special Markdown meanings.
  5. */
  6. showdown.subParser('encodeCode', function (text) {
  7. 'use strict';
  8. // Encode all ampersands; HTML entities are not
  9. // entities within a Markdown code span.
  10. text = text.replace(/&/g, '&');
  11. // Do the angle bracket song and dance:
  12. text = text.replace(/</g, '&lt;');
  13. text = text.replace(/>/g, '&gt;');
  14. // Now, escape characters that are magic in Markdown:
  15. text = showdown.helper.escapeCharacters(text, '*_{}[]\\', false);
  16. // jj the line above breaks this:
  17. //---
  18. //* Item
  19. // 1. Subitem
  20. // special char: *
  21. // ---
  22. return text;
  23. });