*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
include_once(DOKU_INC.'inc/common.php');
include_once(DOKU_INC.'inc/html.php');
include_once(DOKU_INC.'inc/format.php');
require_once(DOKU_INC.'lang/en/lang.php');
require_once(DOKU_INC.'lang/'.$conf['lang'].'/lang.php');
/**
* The main parser function.
*
* Accepts raw data and returns valid xhtml
*
* @author Andreas Gohr \n* ";
$pc = mkToken();
$table[$pc] = "(.*?)
#se","preformat('\\3','code','\\2')");
firstpass($table,$text,"#(.*?)
#","",$line);
$line = preg_replace("#<(file|html|php)>(.*?)\\1>#","",$line);
//check for start of multiline noparse areas
if(preg_match('#^.*?<(nowiki|code|php|html|file)( (\w+))?>#',$line,$matches)){
list($noparse) = split(" ",$matches[1]); //remove options
$noparse = ''.$noparse.'>';
continue;
}elseif(preg_match('#^.*?%%#',$line)){
$noparse = '%%';
continue;
}
}
//handle headlines
if(preg_match('/^(\s)*(==+)(.+?)(==+)(\s*)$/',$lines[$l],$matches)){
//get token
$tk = tokenize_headline($hltable,$matches[2],$matches[3],$l);
//replace line with token
$lines[$l] = $tk;
}
//handle paragraphs
if(empty($lines[$l])){
$lines[$l] = "$pc\n$po";
}
}
//reassemble full text
$text = join("\n",$lines);
//open first and close last paragraph
$text = "$po\n$text\n$pc";
return $text;
}
/**
* Build TOC lookuptable
*
* This function adds some information about the given headline
* to a lookuptable to be processed later. Returns a unique token
* that idetifies the headline later
*
* @author Andreas Gohr
"; //open new paragraph //remember for autoTOC if($hl['level'] <= $conf['maxtoclevel']){ $content[] = array('id' => $hash, 'name' => $hl['name'], 'level' => $hl['level']); } //add link for section edit for HLs 1, and 3 if( ($hl['level'] <= $conf['maxseclevel']) && ($hl['line'] - $last > 1)){ $secedit = ''; $headline = $secedit.$headline; $last = $hl['line']; } //put headline into firstpasstable $table[$hl['token']] = $headline; } //add link for editing the last section if($last){ $secedit = ''; $token = mktoken(); $text .= $token; $table[$token] = $secedit; } //close last div if ($cnt){ $token = mktoken(); $text .= $token; $table[$token] = '
\1
',$text); //code
$text = preg_replace('#<del>(.*?)</del>#is','",$text); //hr
//sub and superscript
$text = preg_replace('#<su([bp])>(.*?)</su\1>#is','
",$text);
// lists (blocks leftover after blockformat)
$text = preg_replace("/(\n( {2,}|\t)[\*\-][^\n]+)(\n( {2,}|\t)[^\n]*)*/se","\"\\n\".listformat('\\0')",$text);
// tables
$text = preg_replace("/\n(([\|\^][^\n]*?)+[\|\^] *\n)+/se","\"\\n\".tableformat('\\0')",$text);
// footnotes
$text = footnotes($text);
// run custom text replacements
$text = customs($text);
return $text;
}
/**
* Footnote formating
*
* @author Andreas Gohr ';
$sm[0] = preg_quote($sm[0],'/');
firstpass($table,$text,'/(?
*/
function acronyms(&$table,&$text){
$acronyms = file('conf/acronyms.conf');
foreach($acronyms as $acro){
$acro = preg_replace('/#.*$/','',$acro); //ignore comments
$acro = trim($acro);
if(empty($acro)) continue;
list($ac,$desc) = preg_split('/\s+/',$acro,2);
$ac = preg_quote($ac,'/');
firstpass($table,$text,'/\b('.$ac.')\b/s',"\\1");
}
}
/**
* Apply custom text replacements
*
* @author Andreas Gohr
"; }elseif($cnt < $lvl){ $ret .= "\n
"; for ($i=0; $i< $lvl - $cnt; $i++){ $ret .= "\n"; }elseif(empty($line)){ $ret .= "
\n"; } //keep rest of line but trim left whitespaces $ret .= ltrim($line)."\n"; //remember level $lvl = $cnt; } //close remaining divs $ret .= "
\n"; for ($i=0; $i< $lvl; $i++){ $ret .= "\n"; } $ret .= "\n";
return "$ret";
}
/**
* format inline tables
*
* @author Andreas Gohr
$data | \n"; // set css class for alignment } else { $ret .= "$data | \n"; // set css class for alignment } } $ret .= "
---|
";
return $ret;
}
/**
* format lists
*
* @author Andreas Gohr
";
}
/**
* Handle preformatted blocks
*
* Uses GeSHi for syntax highlighting
*
* @author Andreas Gohr
".$text."\n
"; break; case 'code': if(empty($option)){ $text = htmlspecialchars($text); $text = '
'.$text.''; }else{ //strip leading blank line $text = preg_replace('/^\s*?\n/','',$text); //use geshi for highlighting require_once("inc/geshi.php"); $geshi = new GeSHi($text, strtolower($option), "inc/geshi"); $geshi->set_encoding($lang['encoding']); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->set_overall_class('code'); $geshi->set_link_target($conf['target']['extern']); $text = $geshi->parse_code(); } $text = "\n".$text."\n
"; break; case 'block': $text = substr($text,1); //remove 1st newline $lines = split("\n",$text); //break into lines $text = ''; foreach($lines as $line){ $text .= substr($line,2)."\n"; //remove indents } $text = htmlspecialchars($text); $text = "
\n".$text."\n
";
break;
}
return $text;
}
/**
* Format embedded media (images)
*
* @author Andreas Gohr