hashHTMLBlocks.js 1.8 KB

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