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', '
  • $1
  • ', $str); return "

    \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', '

  • $1
  • ', $str); if (($start=floor($num))>0 || $num=='0') $type = '1'; else if (strlen($num)==1 && ($start=strpos('$abcdefgh$jklmnopqrstuvwxyz', $num))!==false) $type = 'a'; else if (strlen($num)==1 && ($start=strpos('$ABCDEFGH$JKLMNOPQRSTUVWXYZ', $num))!==false) $type = 'A'; else if (strspn($num, 'IiVvXx')>0) { $type = ctype_lower($num)? 'i' : 'I'; $start = array_search(strtolower($num), array('$', 'i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix', 'x', 'xi', 'xii', 'xiii', 'xiv', 'xv', 'xvi', 'xvii', 'xviii', 'xix', 'xx')); } else $type=$start=1; return "

      $str

    \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 "

    $str

    "; } 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( '@!"(.*?)" \((.*?)\)@', '$1', $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_replace('


    ', '

    ', $str); $str = "

    $str

    "; $str = preg_replace('@

    \s*

    @s', '', $str); return $str; } ?>