blockGamut.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * These are all the transformations that form block-level
  3. * tags like paragraphs, headers, and list items.
  4. */
  5. showdown.subParser('blockGamut', function (text, options, globals) {
  6. 'use strict';
  7. text = globals.converter._dispatch('blockGamut.before', text, options, globals);
  8. // we parse blockquotes first so that we can have headings and hrs
  9. // inside blockquotes
  10. text = showdown.subParser('blockQuotes')(text, options, globals);
  11. text = showdown.subParser('headers')(text, options, globals);
  12. // Do Horizontal Rules:
  13. var key = showdown.subParser('hashBlock')('<hr />', options, globals);
  14. text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm, key);
  15. text = text.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm, key);
  16. text = text.replace(/^[ ]{0,2}([ ]?_[ ]?){3,}[ \t]*$/gm, key);
  17. text = showdown.subParser('lists')(text, options, globals);
  18. text = showdown.subParser('codeBlocks')(text, options, globals);
  19. text = showdown.subParser('tables')(text, options, globals);
  20. // We already ran _HashHTMLBlocks() before, in Markdown(), but that
  21. // was to escape raw HTML in the original Markdown source. This time,
  22. // we're escaping the markup we've just created, so that we don't wrap
  23. // <p> tags around block-level tags.
  24. text = showdown.subParser('hashHTMLBlocks')(text, options, globals);
  25. text = showdown.subParser('paragraphs')(text, options, globals);
  26. text = globals.converter._dispatch('blockGamut.after', text, options, globals);
  27. return text;
  28. });