public function format_text($text, array $options = []) { return DText::parse($text); }
function format_text($text, $options = array()) { return DText::parse($text); }
static function parse($str) { # Make sure quote tags are surrounded by newlines $str = preg_replace('/\\s*\\[quote\\]\\s*/m', "\n\n[quote]\n\n", $str); $str = preg_replace('/\\s*\\[\\/quote\\]\\s*/m', "\n\n[/quote]\n\n", $str); $str = preg_replace('/(?:\\r?\\n){3,}/', "\n\n", $str); $str = trim($str); $blocks = preg_split('/(?:\\r?\\n){2}/', $str); $html = array_map(function ($block) { if (preg_match('/^(h[1-6])\\.\\s*(.+)$/', $block, $m)) { $tag = $m[1]; $content = $m[2]; return '<' . $tag . '>' . DText::parse_inline($content) . '</' . $tag . '>'; } elseif (preg_match('/^\\s*\\*+ /', $block)) { return DText::parse_list($block); } elseif ($block == '[quote]') { return '<blockquote>'; } elseif ($block == '[/quote]') { return '</blockquote>'; } else { return '<p>' . DText::parse_inline($block) . '</p>'; } }, $blocks); return implode('', $html); }