hashHTMLBlocks.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
  2. 'use strict';
  3. text = globals.converter._dispatch('hashHTMLBlocks.before', text, options, globals);
  4. var blockTags = [
  5. 'pre',
  6. 'div',
  7. 'h1',
  8. 'h2',
  9. 'h3',
  10. 'h4',
  11. 'h5',
  12. 'h6',
  13. 'blockquote',
  14. 'table',
  15. 'dl',
  16. 'ol',
  17. 'ul',
  18. 'script',
  19. 'noscript',
  20. 'form',
  21. 'fieldset',
  22. 'iframe',
  23. 'math',
  24. 'style',
  25. 'section',
  26. 'header',
  27. 'footer',
  28. 'nav',
  29. 'article',
  30. 'aside',
  31. 'address',
  32. 'audio',
  33. 'canvas',
  34. 'figure',
  35. 'hgroup',
  36. 'output',
  37. 'video',
  38. 'p'
  39. ],
  40. repFunc = function (wholeMatch, match, left, right) {
  41. var txt = wholeMatch;
  42. // check if this html element is marked as markdown
  43. // if so, it's contents should be parsed as markdown
  44. if (left.search(/\bmarkdown\b/) !== -1) {
  45. txt = left + globals.converter.makeHtml(match) + right;
  46. }
  47. return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
  48. };
  49. for (var i = 0; i < blockTags.length; ++i) {
  50. text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<' + blockTags[i] + '\\b[^>]*>', '</' + blockTags[i] + '>', 'gim');
  51. }
  52. // HR SPECIAL CASE
  53. text = text.replace(/(\n {0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
  54. showdown.subParser('hashElement')(text, options, globals));
  55. // Special case for standalone HTML comments
  56. text = showdown.helper.replaceRecursiveRegExp(text, function (txt) {
  57. return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
  58. }, '^ {0,3}<!--', '-->', 'gm');
  59. // PHP and ASP-style processor instructions (<?...?> and <%...%>)
  60. text = text.replace(/(?:\n\n)( {0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
  61. showdown.subParser('hashElement')(text, options, globals));
  62. text = globals.converter._dispatch('hashHTMLBlocks.after', text, options, globals);
  63. return text;
  64. });