*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); define("BULLET_PNG", DOKU_REL ."lib/plugins/annotate/bullet.png"); //msg(BULLET_PNG); class syntax_plugin_annotate_anno extends DokuWiki_Syntax_Plugin { var $test_str; /** * What kind of syntax are we? */ function getType(){ return 'substition'; } /** * What about paragraphs? */ function getPType(){ //return 'block'; } /** * Where to sort in? */ function getSort(){ return 155; } public function __construct() { $this->test_str = ''; } /** * Connect pattern to lexer */ public function connectTo($mode) { $this->Lexer->addEntryPattern( '<@anno:\d\d?>(?=.*?)',$mode, 'plugin_annotate_anno'); $this->Lexer->addEntryPattern( '<@anno:\[\d\d?;;\w+\]>(?=.*?)',$mode, 'plugin_annotate_anno'); $this->Lexer->addSpecialPattern( '.*?',$mode,'plugin_annotate_anno'); } public function postConnect() { $this->Lexer->addExitPattern('','plugin_annotate_anno'); } /** * Handle the match */ function handle($match, $state, $pos, Doku_Handler $handler){ switch($state) { case DOKU_LEXER_ENTER : $match = str_replace(array(':', ';', '[' , ']'), array('_'," ","",""),substr($match,2,-1)); return array($state, $match); case DOKU_LEXER_UNMATCHED : if(preg_match("/([\w\:]+)\<\/top\>/m",$match,$matches)) { $id = $matches[1]; $text = io_readWikiPage(wikiFN($id, $rev), $id, false); if($text) { $match = preg_replace("/.*?<\/top>/ms", "\n$text\n",$match); } } if(preg_match("/([\w\:]+)\<\/bottom\>/m",$match,$matches)) { $id = $matches[1]; $text = io_readWikiPage(wikiFN($id, $rev), $id, false); if($text) { $match = preg_replace("/.*?<\/bottom>/ms", "\\\\\\ $text",$match); } } return array($state, $match); case DOKU_LEXER_EXIT : return array($state, ''); case DOKU_LEXER_SPECIAL: $inner = substr($match,6,-7); return array($state, $inner); } return array($state, "" ); } /** * Create output */ function render($mode, Doku_Renderer $renderer, $data) { static $last; if($mode == 'xhtml'){ list($state, $xhtml) = $data; switch ($state) { case DOKU_LEXER_ENTER : $classes = preg_split("/\s+/", $xhtml); $xhtml = rtrim(implode(' ',$classes)); $last = $classes[0]; if (count($classes) > 1) { $tip = ''; } else { $tip = ''; } $renderer->doc .= $tip; break; case DOKU_LEXER_UNMATCHED : $renderer->doc .= 'close '; $xhtml = trim($xhtml); if(preg_match('/^\{\{([\w\:]+)\}\}$/',$xhtml,$matches)) { $html = p_wiki_xhtml($matches[1]); } else { $secedit = false; $html = html_secedit(p_render('xhtml',p_get_instructions($xhtml),$info),$secedit); //$info is reference, $secedit is handled by html_secedit } $html = $this->html_filter($html); $renderer->doc .= $html; break; case DOKU_LEXER_EXIT : $renderer->doc .= ""; break; case DOKU_LEXER_SPECIAL: list($which,$text)= explode('>',$xhtml); $title = 'anno_' .$which; $renderer->doc .= '' .htmlentities($text).''; break; } return true; } return false; } function html_filter($html){ $html = str_replace(array('[List]','[tsiL]'),"",$html); $html = preg_replace('/<\/?p>/ms',"",$html); $html = preg_replace_callback('/<(\/)?h(\d).*?>/ms', function($matches){ if($matches[1] == '/'){ $style = ''; if($matches[2] <= 3){ $style .= '
'; } } else { if($matches[2] <= 4){ if($matches[2] == 1) { $style = '
'; } else if($matches[2] == 2) { $style = '
'; } else if($matches[2] == 3) { $style = '
'; } else if($matches[2] == 4) { $style = '
'; } // else $style = '
'; } else $style = '
'; } return $style; }, $html); $html = preg_replace_callback( '/]+>(.*?)<\/table>/ms', function($matches) { $replace = array('td','th',''); $replacements = array('span','span_h','
'); $matches[1] = str_replace($replace, $replacements,$matches[1]); $matches[1] = preg_replace("/\/","",$matches[1]); $matches[1] = preg_replace(array("/\/","/col\d+/"),array("",'anno_col'),$matches[1]); $matches[1] = preg_replace('/\"anno_col\"\s+colspan=\"(\d)\"/',"anno_colspan_$1",$matches[1]); $matches[1] = preg_replace("/span_h\s+class=\"/","span class=\"theader ",$matches[1]); $matches[1] = str_replace('/span_h','/span',$matches[1]); return'
' . $matches[1] .'
'; },$html); $html = preg_replace_callback( '/\<(o|u)l\>([\s\S]+)\<\/(o|u)l\>/ms', function($matches) { $matches[0] = preg_replace("/\/","  ", $matches[0]); $matches[0] = preg_replace('/\/',"",$matches[0]); $matches[0] = str_replace('','
',$matches[0]); return $matches[0] ."\nEOL"; },$html); //$html = preg_replace("/\<\/?(ul|ol|li)\>/","", $html); $html = preg_replace("/\<\/(ul|ol|li)\>/","", $html); $html = preg_replace_callback( '/(\
    |\)(.*?)EOL/ms', function($matches) { $type = ""; /* ol { list-style: decimal outside; } ol ol { list-style-type: lower-alpha; } ol ol ol { list-style-type: upper-roman; } ol ol ol ol { list-style-type: upper-alpha; } ol ol ol ol ol { list-style-type: lower-roman; } */ $anno_li_1 = 0; $anno_li_3 = 'abcdefghijklmnopqrstuvwxyz'; $anno_li_2 = $anno_li_8=$anno_li_7=$anno_li_6 = array('i','ii','iii','iv','v','vi','vii','viii','ix','x','xi','xii','xiii','xiv','xv','xvi','xvii','xviii','xix','xx','xxi','xxii','xxiii','xxiv','xxv','xxvi'); $anno_li_4 = array('I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII','XIII','XIV','XV','XVI','XVII','XVIII','XIX','XX','XXI','XXII','XXIII','XXIV','XXV','XXVI'); $anno_li_5 = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); $current = array('anno_li_0' => 0,'anno_li_1' => 0,'anno_li_2' => 0,'anno_li_3'=>0,'anno_li_4'=>0,'anno_li_5'=>0,'anno_li_6'=>0, 'anno_li_7'=>0,'anno_li_8'=>0); $_list = explode("\n", $matches[2]); $retv = "
    "; for($i=0; $i/",$_list[$i])) { $type = 'o'; continue; } else if(preg_match("/\/",$_list[$i])) { $type = 'u'; continue; } if($type == 'u') { $_list[$i] = str_replace("", "",$_list[$i] ); } else { if(preg_match("/(anno_li_(\d))/",$_list[$i],$match)) { if($match[1] == 'anno_li_1') { $anno_li_1++; $_list[$i] = str_replace(' ',$anno_li_1,$_list[$i]); // Insert current number } else { $b = $match[1]; // anno_li_ $a = ${$b}; // $anno_li_ $marker = $a[$current[$match[1]]]; $_list[$i] = str_replace(' ',$marker,$_list[$i]); $current[$match[1]]++; // $current[ 'anno_li_'] } } } $retv .= $_list[$i] ."\n"; } } return $retv; },$html); $html = str_replace('
    ','

    ',$html); $html = str_replace('
    ', '
    ',$html); $html = str_replace('
    ', '',$html); $html = preg_replace('/<\/?div.*?>/ms',"",$html); $html = preg_replace('//ms',"",$html); return $html; } }