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
|
|
|
|
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];
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-01-19 19:37:21 +08:00
|
|
|
// if this is an HTML marker, copy it
|
|
|
|
if (str.search(/~K(\d+)K/g) >= 0) {
|
|
|
|
grafsOut.push(str);
|
|
|
|
} else if (str.search(/\S/) >= 0) {
|
|
|
|
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++) {
|
|
|
|
// if this is a marker for an html block...
|
|
|
|
while (grafsOut[i].search(/~K(\d+)K/) >= 0) {
|
|
|
|
var blockText = globals.gHtmlBlocks[RegExp.$1];
|
|
|
|
blockText = blockText.replace(/\$/g, '$$$$'); // Escape any dollar signs
|
|
|
|
grafsOut[i] = grafsOut[i].replace(/~K\d+K/, blockText);
|
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
|
|
|
return grafsOut.join('\n\n');
|
2015-01-16 05:21:33 +08:00
|
|
|
});
|