--- dokuwiki-2011-05-25a/lib/plugins/imagereference/syntax.php 2008-09-11 18:29:12.000000000 +1200 +++ dokuwiki/lib/plugins/imagereference/syntax.php 2012-01-19 11:03:52.285067251 +1300 @@ -22,6 +22,7 @@ var $_figure_name_array = array(""); var $_figure_map = array(); + var $_captions = array(); /** @@ -80,13 +81,17 @@ * @see render() */ function connectTo($mode) { + $this->Lexer->addSpecialPattern('',$mode, 'plugin_imagereference'); - $this->Lexer->addEntryPattern('(?=.*?)',$mode,'plugin_imagereference'); - $this->Lexer->addEntryPattern('.*?)',$mode,'plugin_imagereference'); + $this->Lexer->addSpecialPattern('',$mode, 'plugin_imagereference'); + + $this->Lexer->addEntryPattern(']+(?=>.*?)',$mode,'plugin_imagereference'); + $this->Lexer->addEntryPattern(']+(?=>.*?)',$mode,'plugin_imagereference'); } - + function postConnect() { $this->Lexer->addExitPattern('', 'plugin_imagereference'); + $this->Lexer->addExitPattern('', 'plugin_imagereference'); } @@ -120,24 +125,39 @@ * @static */ function handle($match, $state, $pos, &$handler){ - switch ($state) { // ========================================================= case DOKU_LEXER_ENTER : { - /* --------------------------------------------------- */ - $refLabel = trim(substr($match, 11, -1)); + + /* --------------------------------------------------- */ + $refLabel = ''; //trim(substr($match, 11, -1)); + $caption = ''; + if (preg_match('/<(?:img|tbl)caption\s+([^\|]+)\|([^>]+)/', $match, $matches)) + { + $refLabel = $matches[1]; + $caption = $matches[2]; + } // ----------------------------------------------------- $parsedInput = $this->_parseParam($refLabel); - + // ------------------------------------------------------ //$data = $this->_imgstart($parsedInput); // store the figure name from imgcaption array_push($this->_figure_name_array, $parsedInput[0]); - - $this->_figure_map[$parsedInput[0]] = ""; - + + $this->_figure_map[$parsedInput[0]] = ''; + + $this->_captions[$parsedInput[0]] = $caption; + + ///cho '

refLabel:' . $refLabel . '

'; + ///cho '

parsedInput:' . print_r($parsedInput, true) . '

'; + ///cho '

figure_name_array: ' . print_r($this->_figure_name_array, true) . '

'; + ///cho '

figure_map: ' . print_r($this->_figure_map, true) . '

'; + ///cho '

captions: ' . print_r($this->_captions, true). '

'; + return array('caption_open', $parsedInput); // image anchor label /* --------------------------------------------------- */ + //} } // ========================================================= case DOKU_LEXER_UNMATCHED : { @@ -191,7 +211,6 @@ * @see handle() */ function render($mode, &$renderer, $indata) { - list($case, $data) = $indata; if($mode == 'xhtml'){ // --------------------------------------------- @@ -200,8 +219,14 @@ /* --------------------------------------- */ $refNumber = array_search($data, $this->_figure_name_array); if ($refNumber == null || $refNumber == "") - $refNumber = "##"; - $str = "".$this->getLang('figure').$refNumber." "; + { + $refNumber = "##"; + } + if (strpos($data,'#') === false) + { + $data = "#" . $data; + } + $str = "".$this->getLang('figure').$refNumber.""; $renderer->doc .= $str; break; // $renderer->_xmlEntities($str);break; /* --------------------------------------- */ @@ -210,10 +235,26 @@ case 'caption_close' : { // ------------------------------------------------------- list($name, $number, $caption) = $data; - $layout = "
".$this->getLang('fig').$number.": - ".$caption." -
"; - $renderer->doc .= $layout; break; + // - retrieve the caption separately + $caption = $this->_captions[$name]; + // - special case for 'hidden' tables + $layout = ''; + if ($caption != '##HIDDEN##') + { + // - manual do any formatting (as leaving it to the + // parser (to foobar) is why we had to do this in + // the first place + $caption = preg_replace('/\/\/%%(.+?)%%\/\//','\1',$caption); + $caption = preg_replace('/\/\/(.+?)\/\//','\1',$caption); + $caption = preg_replace('/\*\*(.+?)\*\*/','\1',$caption); + $caption = str_replace('%!--', '', $caption); + // - special case: nested image ref (we can't really resolve these) + $caption = preg_replace('/]+)><\/imgref>/','\1',$caption); + $layout = "
".$this->getLang('fig').$number.": ".$caption."
"; + } + $layout .= ""; + $renderer->doc .= $layout; break; } // ------------------------------------------------------- // data is mostly empty!!! @@ -284,7 +325,7 @@ function _imgstart($str) { // ============================================ // - if (!strlen($str)) return array(); + if (empty($str)) return ''; $layout = "
_figure_name_array); // get the position of the figure in the array @@ -311,8 +354,9 @@ return array($figureName, $refNumber, $str); + $layout = "
".$this->getLang('fig').$refNumber.": - _figure_name_array)."\">".$str."
"; + _figure_name_array)."\">".$str."
"; //$layout = "
Fig. ".$refNumber.": //_figure_name_array)."\">".$str."
";