2015-01-16 05:21:33 +08:00
|
|
|
showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
|
2015-01-19 19:37:21 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-01-02 07:33:33 +08:00
|
|
|
var blockTags = [
|
|
|
|
'pre',
|
|
|
|
'div',
|
|
|
|
'h1',
|
|
|
|
'h2',
|
|
|
|
'h3',
|
|
|
|
'h4',
|
|
|
|
'h5',
|
|
|
|
'h6',
|
|
|
|
'blockquote',
|
|
|
|
'table',
|
|
|
|
'dl',
|
|
|
|
'ol',
|
|
|
|
'ul',
|
|
|
|
'script',
|
|
|
|
'noscript',
|
|
|
|
'form',
|
|
|
|
'fieldset',
|
|
|
|
'iframe',
|
|
|
|
'math',
|
|
|
|
'style',
|
|
|
|
'section',
|
|
|
|
'header',
|
|
|
|
'footer',
|
|
|
|
'nav',
|
|
|
|
'article',
|
|
|
|
'aside',
|
|
|
|
'address',
|
|
|
|
'audio',
|
|
|
|
'canvas',
|
|
|
|
'figure',
|
|
|
|
'hgroup',
|
|
|
|
'output',
|
|
|
|
'video',
|
|
|
|
'p'
|
|
|
|
],
|
2016-01-02 09:08:17 +08:00
|
|
|
repFunc = function (wholeMatch, match, left, right) {
|
|
|
|
var txt = wholeMatch;
|
|
|
|
// check if this html element is marked as markdown
|
|
|
|
// if so, it's contents should be parsed as markdown
|
|
|
|
if (left.search(/\bmarkdown\b/) !== -1) {
|
|
|
|
txt = left + globals.converter.makeHtml(match) + right;
|
|
|
|
}
|
2017-01-29 08:07:19 +08:00
|
|
|
return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
|
2016-01-02 07:33:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < blockTags.length; ++i) {
|
2016-08-30 13:24:19 +08:00
|
|
|
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<' + blockTags[i] + '\\b[^>]*>', '</' + blockTags[i] + '>', 'gim');
|
2016-01-02 07:33:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// HR SPECIAL CASE
|
2016-08-30 13:07:57 +08:00
|
|
|
text = text.replace(/(\n {0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
|
2016-01-02 07:33:33 +08:00
|
|
|
showdown.subParser('hashElement')(text, options, globals));
|
2015-01-19 19:37:21 +08:00
|
|
|
|
2016-08-30 13:07:57 +08:00
|
|
|
// Special case for standalone HTML comments
|
|
|
|
text = showdown.helper.replaceRecursiveRegExp(text, function (txt) {
|
2017-01-29 08:07:19 +08:00
|
|
|
return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
|
2016-08-30 13:24:19 +08:00
|
|
|
}, '^ {0,3}<!--', '-->', 'gm');
|
2015-01-19 19:37:21 +08:00
|
|
|
|
|
|
|
// PHP and ASP-style processor instructions (<?...?> and <%...%>)
|
2016-08-30 13:24:19 +08:00
|
|
|
text = text.replace(/(?:\n\n)( {0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
|
2016-01-02 07:33:33 +08:00
|
|
|
showdown.subParser('hashElement')(text, options, globals));
|
2015-01-19 19:37:21 +08:00
|
|
|
|
|
|
|
return text;
|
2015-01-16 05:21:33 +08:00
|
|
|
});
|