private string FormParagraphs(string text, bool unhash = true)
{
// split on two or more newlines
string[] grafs = _newlinesMultiple.Split(_newlinesLeadingTrailing.Replace(text, ""));
for (int i = 0; i < grafs.Length; i++)
{
if (grafs[i].StartsWith("\x1AH"))
{
// unhashify HTML blocks
if (unhash)
{
int sanityCheck = 50; // just for safety, guard against an infinite loop
bool keepGoing = true; // as long as replacements where made, keep going
while (keepGoing && sanityCheck > 0)
{
keepGoing = false;
grafs[i] = _htmlBlockHash.Replace(grafs[i], match =>
{
keepGoing = true;
return _htmlBlocks[match.Value];
});
sanityCheck--;
}
/* if (keepGoing)
{
// Logging of an infinite loop goes here.
// If such a thing should happen, please open a new issue on http://code.google.com/p/markdownsharp/
// with the input that caused it.
}*/
}
}
else
{
// do span level processing inside the block, then wrap result in <p> tags
grafs[i] = _leadingWhitespace.Replace(RunSpanGamut(grafs[i]), "<p>") + "</p>";
}
}
return string.Join("\n\n", grafs);
}