/", "<$1>", $str); $str = preg_replace("/[\\\]{2} +/", "
", $str); $str = preg_replace("/\*\*([^\*]*)\*\*/", "$1", $str); $str = preg_replace("/\/\/([^\/\[\]\{\}]*)\/\//", "$1", $str); $str = preg_replace("/__([^_]*)__/", "$1", $str); $str = preg_replace("/--([^-]*)--/", "$1", $str); $str = preg_replace("/\[\[http:\/\/([^\|\]]*)\|([^\]]*)\]\]/", '$2', $str); $str = preg_replace("/\[\[http:\/\/([^\|\]]*)\]\]/", '$1', $str); $str = preg_replace("/\{\{http:\/\/([^\|\}\? ]*)\}\}/", '$1', $str); $str = preg_replace("/\{\{http:\/\/([^\|\}\? ]*)\?([0-9]*)\}\}/", '$1', $str); $str = preg_replace("/\{\{http:\/\/([^\|\}\? ]*)\?([0-9]*)x([0-9]*)\}\}/", '$1', $str); $str = preg_replace("/\{\{http:\/\/([^\|\}\? ]*) *\}\}/", '$1', $str); $str = preg_replace("/\{\{http:\/\/([^\|\}\? ]*)\?([0-9]*) *\}\}/", '$1', $str); $str = preg_replace("/\{\{http:\/\/([^\|\}\? ]*)\?([0-9]*)x([0-9]*) *\}\}/", '$1', $str); $str = preg_replace("/\{\{ +http:\/\/([^\|\}\? ]*)\}\}/", '$1', $str); $str = preg_replace("/\{\{ +http:\/\/([^\|\}\? ]*)\?([0-9]*)\}\}/", '$1', $str); $str = preg_replace("/\{\{ +http:\/\/([^\|\}\? ]*)\?([0-9]*)x([0-9]*)\}\}/", '$1', $str); $str = preg_replace("/\{\{ +http:\/\/([^\|\}\? ]*) +\}\}/", '$1', $str); $str = preg_replace("/\{\{ +http:\/\/([^\|\}\? ]*)\?([0-9]*) +\}\}/", '$1', $str); $str = preg_replace("/\{\{ +http:\/\/([^\|\}\? ]*)\?([0-9]*)x([0-9]*) +\}\}/", '$1', $str); $str = preg_replace("/< ?\.([^\| ]*) ?\|([^>]*)>/", '$2', $str); $str = preg_replace("/< ?= ?([^\| ]*) ?\|([^>]*)>/", '$2', $str); if ($add_p){ $result .= "

".$str."

\n"; }else{ $result .= $str; } } return $result; } function cording_div($buffer){ $start_line = array_shift($buffer); if (preg_match("/^\#([^\.\#]*) ?\.([^\.\#\{]*)\{$/", $start_line, $data)){ $result = '
'."\n"; }else if (preg_match("/^\.([^\.\#]*) ?\#([^\.\#\{]*)\{$/", $start_line, $data)){ $result = '
'."\n"; }else if (preg_match("/^\.([^\.\#\{]*)\{$/", $start_line, $data)){ $result = '
'."\n"; }else if (preg_match("/^\#([^\.\#\{]*)\{$/", $start_line, $data)){ $result = '
'."\n"; } array_pop($buffer); $result .= $this->cording_p($buffer)."
\n"; return $result; } function cording_table($buffer){} function cording_list($buffer){ $end = count($buffer); for ($i=0; $i<$end; $i++){ $line = $buffer[$i]; if (preg_match("/^([ ]+)- ?(.*)$/", $line, $data)){ $list[$i] = array('type' => 'ol', 'level' => floor(strlen($data[1])/2), 'body' => $data[2]); }else if (preg_match("/^([ ]+)\* ?(.*)$/", $line, $data)){ $list[$i] = array('type' => 'ul', 'level' => floor(strlen($data[1])/2), 'body' => $data[2]); } } $line = $list[0]; $last_type = $line['type']; $last_level = $line['level']; $open_tag = array($last_type); $result = "<".$last_type.' class="level_'.$last_level.'">'."\n".str_repeat(" ", ($last_level-1)*2+2).'
  • '.$this->cording_p(array($line['body']), FALSE)."
  • \n"; for ($i=1; $i<$end; $i++){ $line = $list[$i]; $now_type = $line['type']; $now_level = $line['level']; if ($now_level > $last_level){ array_unshift($open_tag, $now_type); $result .= str_repeat(" ", ($last_level-1)*2+2)."<".$now_type.' class="level_'.$now_level.'">'."\n".str_repeat(" ", ($now_level-1)*2+2).'
  • '.$this->cording_p(array($line['body']), FALSE)."
  • \n"; }else if ($now_level < $last_level){ array_shift($open_tag); $result .= str_repeat(" ", ($last_level-1)*2)."\n".str_repeat(" ", ($now_level-1)*2+2).'
  • '.$this->cording_p(array($line['body']), FALSE)."
  • \n"; }else{ $result .= str_repeat(" ", ($now_level-1)*2+2).'
  • '.$this->cording_p(array($line['body']), FALSE)."
  • \n"; } $last_type = $now_type; $last_level = $now_level; } $end = count($open_tag); for ($i=0; $i<$end; $i++){ $line = $open_tag[$i]; $result .= str_repeat(" ", ($last_level-1)*2)."\n"; $last_level --; } return $result; } function cording_blockquote($buffer){} function cording_code($buffer){} function cording_heading($buffer){ $end = count($buffer); for ($i=0; $i<$end; $i++){ $str = $buffer[$i]; $str = preg_replace("/^===== ?([^\=]*)$/", "
    $1
    \n", $str); $str = preg_replace("/^==== ?([^\=]*)$/", "

    $1

    \n", $str); $str = preg_replace("/^=== ?([^\=]*)$/", "

    $1

    \n", $str); $str = preg_replace("/^== ?([^\=]*)$/", "

    $1

    \n", $str); $result .= $str; } return $result; } function get_type($line){ $str1 = substr($line, 0, 1); $str2 = substr($line, 0, 2); $str3 = substr($line, 0, 3); static $mode_fix = FALSE; static $result; if ($line == ""){ $result = "EOF"; }else if (!$mode_fix){ if ($str2 === "=="){ $result = "cording_heading"; }else if (preg_match("/^[\^\|]([^\^\|]*)[\^\|]/",$line)){ $result = "cording_table"; }else if (preg_match("/^ +[\*-](.*)/", $line)){ $result = "cording_list"; }else if (preg_match("/^$/", $line)){ $result = "cording_code"; $mode_fix = TRUE; }else if (preg_match("/^[\.\#]([^\{]*)\{$/", $line)){ $result = "cording_div"; $mode_fix = TRUE; }else if ($line === "}"){ $result = "cording_div"; }else{ $result = "cording_p"; } }else if (($result === "cording_code" && $line === '</code>') || ($result === "cording_div" && $line === "}")){ $mode_fix = FALSE; } return $result; } function is_buffer($current_line, $follow_line){ global $_cording; $result = FALSE; if (($_cording = $this->get_type($current_line)) == $this->get_type($follow_line)){ $result = TRUE; } return $result; } function cording_start($text){ global $_cording; $corded = array(); $buffer = array(); $before_cording = preg_split("/[\r\n]/", $text, -1, PREG_SPLIT_NO_EMPTY); $end = count($before_cording); for ($i=0; $i<$end; $i++){ $current_line = $before_cording[$i]; $follow_line = $before_cording[$i+1]; array_push ($buffer, $current_line); if (!$this->is_buffer($current_line, $follow_line)){ array_push ($corded, $this->$_cording($buffer)); $buffer = array(); } } $this->cording_finish($corded); } function cording_finish($corded = array()){ while ($line = array_shift($corded)){ echo $line."\n"; } } } ?>