2015-01-16 05:21:33 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
showdown.subParser('paragraphs', function (text, options, globals) {
|
2015-01-19 19:37:21 +08:00
|
|
|
'use strict';
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2016-03-21 01:08:44 +08:00
|
|
|
text = globals.converter._dispatch('paragraphs.before', text, options, globals);
|
2015-01-19 19:37:21 +08:00
|
|
|
// Strip leading and trailing lines:
|
|
|
|
text = text.replace(/^\n+/g, '');
|
|
|
|
text = text.replace(/\n+$/g, '');
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-01-19 22:57:43 +08:00
|
|
|
var grafs = text.split(/\n{2,}/g),
|
|
|
|
grafsOut = [],
|
|
|
|
end = grafs.length; // Wrap <p> tags
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-01-19 19:37:21 +08:00
|
|
|
for (var i = 0; i < end; i++) {
|
|
|
|
var str = grafs[i];
|
|
|
|
// if this is an HTML marker, copy it
|
2017-01-29 08:07:19 +08:00
|
|
|
if (str.search(/¨(K|G)(\d+)\1/g) >= 0) {
|
2015-01-19 19:37:21 +08:00
|
|
|
grafsOut.push(str);
|
2017-01-31 04:43:56 +08:00
|
|
|
|
|
|
|
// test for presence of characters to prevent empty lines being parsed
|
|
|
|
// as paragraphs (resulting in undesired extra empty paragraphs)
|
|
|
|
} else if (str.search(/\S/) >= 0) {
|
2015-01-19 19:37:21 +08:00
|
|
|
str = showdown.subParser('spanGamut')(str, options, globals);
|
|
|
|
str = str.replace(/^([ \t]*)/g, '<p>');
|
|
|
|
str += '</p>';
|
|
|
|
grafsOut.push(str);
|
2015-01-16 05:21:33 +08:00
|
|
|
}
|
2015-01-19 19:37:21 +08:00
|
|
|
}
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-01-19 19:37:21 +08:00
|
|
|
/** Unhashify HTML blocks */
|
|
|
|
end = grafsOut.length;
|
|
|
|
for (i = 0; i < end; i++) {
|
2016-01-25 09:04:06 +08:00
|
|
|
var blockText = '',
|
|
|
|
grafsOutIt = grafsOut[i],
|
|
|
|
codeFlag = false;
|
2015-01-19 19:37:21 +08:00
|
|
|
// if this is a marker for an html block...
|
2017-02-06 03:57:24 +08:00
|
|
|
// use RegExp.test instead of string.search because of QML bug
|
|
|
|
while (/¨(K|G)(\d+)\1/.test(grafsOutIt)) {
|
2016-01-25 09:04:06 +08:00
|
|
|
var delim = RegExp.$1,
|
|
|
|
num = RegExp.$2;
|
|
|
|
|
|
|
|
if (delim === 'K') {
|
|
|
|
blockText = globals.gHtmlBlocks[num];
|
|
|
|
} else {
|
|
|
|
// we need to check if ghBlock is a false positive
|
2016-01-25 11:01:54 +08:00
|
|
|
if (codeFlag) {
|
|
|
|
// use encoded version of all text
|
2017-01-30 03:28:30 +08:00
|
|
|
blockText = showdown.subParser('encodeCode')(globals.ghCodeBlocks[num].text, options, globals);
|
2016-01-25 11:01:54 +08:00
|
|
|
} else {
|
|
|
|
blockText = globals.ghCodeBlocks[num].codeblock;
|
|
|
|
}
|
2016-01-25 09:04:06 +08:00
|
|
|
}
|
2015-01-19 19:37:21 +08:00
|
|
|
blockText = blockText.replace(/\$/g, '$$$$'); // Escape any dollar signs
|
2016-01-25 09:04:06 +08:00
|
|
|
|
2017-01-29 08:07:19 +08:00
|
|
|
grafsOutIt = grafsOutIt.replace(/(\n\n)?¨(K|G)\d+\2(\n\n)?/, blockText);
|
2016-01-25 09:04:06 +08:00
|
|
|
// Check if grafsOutIt is a pre->code
|
|
|
|
if (/^<pre\b[^>]*>\s*<code\b[^>]*>/.test(grafsOutIt)) {
|
|
|
|
codeFlag = true;
|
|
|
|
}
|
2015-01-16 05:21:33 +08:00
|
|
|
}
|
2016-01-25 09:04:06 +08:00
|
|
|
grafsOut[i] = grafsOutIt;
|
2015-01-19 19:37:21 +08:00
|
|
|
}
|
2016-09-29 07:50:58 +08:00
|
|
|
text = grafsOut.join('\n');
|
2016-01-25 09:04:06 +08:00
|
|
|
// Strip leading and trailing lines:
|
|
|
|
text = text.replace(/^\n+/g, '');
|
|
|
|
text = text.replace(/\n+$/g, '');
|
2016-03-21 01:08:44 +08:00
|
|
|
return globals.converter._dispatch('paragraphs.after', text, options, globals);
|
2015-01-16 05:21:33 +08:00
|
|
|
});
|