| 27 | 27 | text = globals.converter._dispatch('unhashHTMLSpans.after', text, options, globals); |
| 28 | 28 | return text; |
| 29 | 29 | }); |
| 30 | | - |
| 31 | | - showdown.subParser('hashHTMLBlocks', function (text, options, globals) { |
| 32 | | - 'use strict'; |
| 33 | | - text = globals.converter._dispatch('hashHTMLBlocks.before', text, options, globals); |
| 34 | | - |
| 35 | | - var blockTags = [ |
| 36 | | - 'pre', |
| 37 | | - 'div', |
| 38 | | - 'h1', |
| 39 | | - 'h2', |
| 40 | | - 'h3', |
| 41 | | - 'h4', |
| 42 | | - 'h5', |
| 43 | | - 'h6', |
| 44 | | - 'blockquote', |
| 45 | | - 'table', |
| 46 | | - 'dl', |
| 47 | | - 'ol', |
| 48 | | - 'ul', |
| 49 | | - 'script', |
| 50 | | - 'noscript', |
| 51 | | - 'form', |
| 52 | | - 'fieldset', |
| 53 | | - 'iframe', |
| 54 | | - 'math', |
| 55 | | - 'style', |
| 56 | | - 'section', |
| 57 | | - 'header', |
| 58 | | - 'footer', |
| 59 | | - 'nav', |
| 60 | | - 'article', |
| 61 | | - 'aside', |
| 62 | | - 'address', |
| 63 | | - 'audio', |
| 64 | | - 'canvas', |
| 65 | | - 'figure', |
| 66 | | - 'hgroup', |
| 67 | | - 'output', |
| 68 | | - 'video', |
| 69 | | - 'details', |
| 70 | | - 'p', |
| 71 | | - // New additions |
| 72 | | - 'svg', |
| 73 | | - ], |
| 74 | | - repFunc = function (wholeMatch, match, left, right) { |
| 75 | | - var txt = wholeMatch; |
| 76 | | - // check if this html element is marked as markdown |
| 77 | | - // if so, it's contents should be parsed as markdown |
| 78 | | - if (left.search(/\bmarkdown\b/) !== -1) { |
| 79 | | - txt = left + globals.converter.makeHtml(match) + right; |
| 80 | | - } |
| 81 | | - return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n'; |
| 82 | | - }; |
| 83 | | - |
| 84 | | - if (options.backslashEscapesHTMLTags) { |
| 85 | | - // encode backslash escaped HTML tags |
| 86 | | - text = text.replace(/\\<(\/?[^>]+?)>/g, function (wm, inside) { |
| 87 | | - return '<' + inside + '>'; |
| 88 | | - }); |
| 89 | | - } |
| 90 | | - |
| 91 | | - // hash HTML Blocks |
| 92 | | - for (var i = 0; i < blockTags.length; ++i) { |
| 93 | | - |
| 94 | | - var opTagPos, |
| 95 | | - rgx1 = new RegExp('^ {0,3}(<' + blockTags[i] + '\\b[^>]*>)', 'im'), |
| 96 | | - patLeft = '<' + blockTags[i] + '\\b[^>]*>', |
| 97 | | - patRight = '</' + blockTags[i] + '>'; |
| 98 | | - // 1. Look for the first position of the first opening HTML tag in the text |
| 99 | | - while ((opTagPos = showdown.helper.regexIndexOf(text, rgx1)) !== -1) { |
| 100 | | - |
| 101 | | - // if the HTML tag is \ escaped, we need to escape it and break |
| 102 | | - |
| 103 | | - |
| 104 | | - //2. Split the text in that position |
| 105 | | - var subTexts = showdown.helper.splitAtIndex(text, opTagPos), |
| 106 | | - //3. Match recursively |
| 107 | | - newSubText1 = showdown.helper.replaceRecursiveRegExp(subTexts[1], repFunc, patLeft, patRight, 'im'); |
| 108 | | - |
| 109 | | - // prevent an infinite loop |
| 110 | | - if (newSubText1 === subTexts[1]) { |
| 111 | | - break; |
| 112 | | - } |
| 113 | | - text = subTexts[0].concat(newSubText1); |
| 114 | | - } |
| 115 | | - } |
| 116 | | - // HR SPECIAL CASE |
| 117 | | - text = text.replace(/(\n {0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g, |
| 118 | | - showdown.subParser('hashElement')(text, options, globals)); |
| 119 | | - |
| 120 | | - // Special case for standalone HTML comments |
| 121 | | - text = showdown.helper.replaceRecursiveRegExp(text, function (txt) { |
| 122 | | - return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n'; |
| 123 | | - }, '^ {0,3}<!--', '-->', 'gm'); |
| 124 | | - |
| 125 | | - // PHP and ASP-style processor instructions (<?...?> and <%...%>) |
| 126 | | - text = text.replace(/\n\n( {0,3}<([?%])[^\r]*?\2>[ \t]*(?=\n{2,}))/g, |
| 127 | | - showdown.subParser('hashElement')(text, options, globals)); |
| 128 | | - |
| 129 | | - text = globals.converter._dispatch('hashHTMLBlocks.after', text, options, globals); |
| 130 | | - return text; |
| 131 | | - }); |
| 132 | 30 | } |