handle){
fclose($this->handle);
}
}
function load($file){
$this->handle = @fopen($file, "r");
$this->title = fgets($this->handle,1024);
fgets($this->handle,512);
fgets($this->handle,512);
}
function fetch(){
return $this->display(1);
}
function display($fetch=false){
if ($this->handle) {
if($fetch){
ob_start();
}
while (!feof($this->handle)) {
echo $this->process(fgets($this->handle, 4096));
}
if($fetch){
$return = ob_get_contents();
ob_end_clean();
return $return;
}
}
}
function parse($content){
ob_start();
foreach(explode("\n",$content) as $line){
$line =trim($line);
echo $this->process($line."\n");
}
$return = ob_get_contents();
ob_end_clean();
return $return;
}
function process($line){
if($this->_in_pre){
if(trim($line)=="```"){
$this->_in_pre = false;
return '';
}else{
return htmlspecialchars($line);
}
}
if(trim($line)==''){
if($this->_last_line_is_empty){
if(($this->_blocks[0]=='ol' || $this->_blocks[0]=='ul')){
return ''.array_shift($this->_blocks).'>';
}else{
return '
';
}
}
$this->_last_line_is_empty = true;
return '
';
}
if(!$this->_in_p){
$this->_in_p = true;
echo '';
}
return $this->fixline($line);
}
function block_re(){
return array(
'/^%/'=>'skip',
'/^\+(=+).*?(=+)(\+)\s*$/'=>'title',
'/^(=+).*?(=+)()\s*$/'=>'title',
'/^([-+])\s(.*)/'=>'list',
'/^(\|{1,2})\s(.+)\s\|{1,2}\s*$/'=>'table',
);
}
function proc_table($match){
$code = $match[1]=='|'?'td':'th';
$line = '
';
foreach(explode(' | ',$match[2]) as $col){
$line .= '<'.$code.'>'.$this->fixline($col).''.$code.'>';
}
$line.=' ';
if(!$this->_in_table){
$this->_in_table = true;
return '