Lexer->addEntryPattern('(?=.*?)',$mode,'plugin_chem'); }
function postConnect() { $this->Lexer->addExitPattern('','plugin_chem'); }
function handle($match, $state, $pos, Doku_Handler $handler){
switch ($state) {
case DOKU_LEXER_ENTER :return array($state, '');
case DOKU_LEXER_UNMATCHED :return array($state, $match);
case DOKU_LEXER_EXIT :return array($state, '');
}
return array();
}
function render($mode, Doku_Renderer $renderer, $data) {
if($mode == 'xhtml' || $mode=='odt'){
list($state, $match) = $data;
switch ($state) {
case DOKU_LEXER_ENTER:break;
case DOKU_LEXER_UNMATCHED:
if($mode=='xhtml'){
// xhtml
$renderer->doc .= $this->getChemFormat($match);
}else{
// Open document format
if (!class_exists('ODTDocument')) {
$this->renderOdtChemFormat($renderer, $match);
} else {
$c = $this->getChemFormat($match);
$renderer->generateSpansfromHTMLCode($c);
}
}
break;
case DOKU_LEXER_EXIT:break;
}
return true;
}
return false;
}
function getChemFormat($raw){
$pattern = array("/([A-Za-z\]\)]+)(0)/", "/[\|]?([0-9]*)[\^]/", "/([^ ][\]\)]?)[\|]?(([\-\+][0-9]*)|([0-9]*[\-\+]))/", "/([A-Z]|[a-z]|\)|\])([1-9][0-9]*)/");
$replace = array("\${1}\${2}", "\${1}", "\${1}\${2}","\${1}\${2}");
return preg_replace($pattern,$replace,$raw);
}
function getOdtChemFormat($raw){
$c = $this->getChemFormat($raw);
$pattern = array("/([^<]+)<\/sup>/","/([^<]+)<\/sub>/");
$replace = array("\${1}",
"\${1}");
return preg_replace($pattern,$replace,$c);
}
}
?>