function MarkdownExtra_Parser::formParagraphs in Markdown 6
Same name and namespace in other branches
- 5 markdown.php \MarkdownExtra_Parser::formParagraphs()
Overrides Markdown_Parser::formParagraphs
File
- ./
markdown.php, line 2995
Class
Code
function formParagraphs($text) {
#
# Params:
# $text - string to process with html <p> tags
#
# Strip leading and trailing lines:
$text = preg_replace('/\\A\\n+|\\n+\\z/', '', $text);
$grafs = preg_split('/\\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY);
#
# Wrap <p> tags and unhashify HTML blocks
#
foreach ($grafs as $key => $value) {
$value = trim($this
->runSpanGamut($value));
# Check if this should be enclosed in a paragraph.
# Clean tag hashes & block tag hashes are left alone.
$is_p = !preg_match('/^B\\x1A[0-9]+B|^C\\x1A[0-9]+C$/', $value);
if ($is_p) {
$value = "<p>{$value}</p>";
}
$grafs[$key] = $value;
}
# Join grafs in one text, then unhash HTML tags.
$text = implode("\n\n", $grafs);
# Finish by removing any tag hashes still present in $text.
$text = $this
->unhash($text);
return $text;
}