0) $str = preg_replace('/^'.str_repeat(' ', $spc).'/m', '', $str); $str = preg_replace_callback( '/(?:^ +[-+*] .+(?:\n +.+)*(?:\n|\Z)){2,}/m', 'parseUl', $str); $str = preg_replace( '/^[-+*] ([^\n]+)(?:\n|\Z)/m', '
\n"; } function parseOl ($m) { $str = $m[0]; $spc = strspn($str, ' '); if ($spc>0) $str = preg_replace('/^'.str_repeat(' ', $spc).'/m', '', $str); $num = substr($str, 0, strcspn($str, ' .)-')); $str = preg_replace_callback( '/(?:^ +(?:\d+|[a-zA-Z]|[IiVvXx]{2,4}) ?[-.)] .+(?:\n +.+)*(?:\n|\Z)){2,}/m', 'parseOl', $str); $str = preg_replace( '/^(?:\d+|[a-zA-Z]|[IiVvXx]{2,4}) ?[-.)] ([^\n]+)(?:\n|\Z)/m', '
\n"; } function parseQuote ($m) { $str = $m[0]; $str = preg_replace( '/^>\s*/m', '', $str); return "
$str
"; } function parseHeading ($m) { $hlvl = floor($_SERVER['hlvl']); $num = strlen($m[1]) + $hlvl -1; $str = trim($m[2]); return "
"; } function markdownize ($str, $hlvl=0) { $str = htmlspecialchars($str); $str = str_replace("\r\n", "\n", $str); if ($hlvl>0) { $_SERVER['hlvl'] = $hlvl; $str = preg_replace_callback( '/^(=+)([^\r\n]+)/m', 'parseHeading', $str); } $str = preg_replace('/``(.*?)``/ms', '
$1
', $str);
$str = preg_replace_callback( '/^> [^\n]+(?:(?:\n\n> |\n)[^\n]+)*/m', 'parseQuote', $str);
$str = preg_replace_callback( '/(?:^[-+*] .+(?:\n.+)*(?:\n|\Z)){2,}/m', 'parseUl', $str);
$str = preg_replace_callback( '/(?:^(?:\d+|[a-zA-Z]|[IiVvXx]{2,4}) ?[-.)] .+(?:\n.+)*(?:\n|\Z)){2,}/m', 'parseOl', $str);
$str = preg_replace( '/\*(?=[\pL\pN])(.*?)(?<=[\pL\pN])\*/su', '$1', $str);
$str = preg_replace( '/--(?=[\pL\pN])(.*?)(?<=[\pL\pN])--/su', '$1', $str);
$str = preg_replace('/`(.*?)`/sm', '$1
', $str);
$str = preg_replace( '@!"(.*?)" \((.*?)\)@', '', $str);
if ($hlvl>0) {
$str = preg_replace( '@"(.*?)" \((.*?)\)@', '$1', $str);
$str = preg_replace('@(?]+)@', '$1', $str);
} else {
$str = preg_replace( '@"(.*?)" \((.*?)\)@', '$1', $str);
$str = preg_replace('@(?]+)@', '$1', $str);
}
$str = str_replace("\n", '
', $str);
$str = str_replace('
', '
', $str);
$str = str_replace('
', '
', $str); $str = "
$str
"; $str = preg_replace('@\s*
@s', '', $str); return $str; } ?>