'Tom N Harris', 'email' => 'tnharris@whoopdedo.org', 'date' => 'Sat, Feb 03, 2007', 'name' => 'Column List Plugin', 'desc' => 'Display a list of items formatted as columns. Syntax: , ... Default formatting is 4 columns. Add ~~COL:~~ before the first item to change this.', 'url' => 'http://whoopdedo.org/doku/wiki'); } function getType() { return 'container'; } function getPType() { return 'block'; } function getSort() { return 19; } function accepts($mode) { if (!count($this->allowedModes)) { global $PARSER_MODES; $this->allowedModes = array_merge($PARSER_MODES['formatting'], $PARSER_MODES['substition'], $PARSER_MODES['protected'], $PARSER_MODES['disabled']); } return parent::accepts($mode); } function connectTo($mode) { $this->Lexer->addEntryPattern('\n {2,},', $mode, 'plugin_columnlist'); $this->Lexer->addEntryPattern('\n\t{1,},', $mode, 'plugin_columnlist'); $this->Lexer->addEntryPattern('~~COL:\d+~~', $mode, 'plugin_columnlist'); $this->Lexer->addPattern('\n {2,},', 'plugin_columnlist'); $this->Lexer->addPattern('\n\t{1,},', 'plugin_columnlist'); } function postConnect() { $this->Lexer->addExitPattern('\n', 'plugin_columnlist'); } function handle($match, $state, $pos, &$handler){ if (substr($match,0,6) == '~~COL:') { $n = (int)substr($match, 6, -2); if ($n != 0) { $this->columns = $n; } } $tags = array(); switch ($state) { case DOKU_LEXER_EXIT: $tags[] = 'end_col'; $this->cur_col = 0; $this->columns = 4; break; case DOKU_LEXER_ENTER: $tags[] = 'open_col'; $tags[] = $this->columns; $this->cur_col = 0; if (substr($match,0,6) == '~~COL:') break; case DOKU_LEXER_MATCHED: $this->cur_col++; if ($this->cur_col > $this->columns) { $tags[] = 'break'; $this->cur_col = 1; } else { $tags[] = 'col'; } break; case DOKU_LEXER_UNMATCHED: return array(false, $match); } return $tags; } function render($format, &$renderer, $data) { static $column = 4; static $cur_col = 0; if (substr($format,0,5) == 'xhtml'){ if ($data[0] !== false) { while ($tag = array_shift($data)) { switch ($tag) { case 'open_col': $columns = array_shift($data); if (!$columns) $columns = 4; $renderer->doc .= ""; $p = (int)(100 / $columns); for ($n=0;$n<$columns;$n++) $renderer->doc .= ""; $renderer->doc .= ""; $cur_col = 0; break; case 'col': if ($cur_col > 0) $renderer->doc .= ""; $renderer->doc .= ""; $renderer->doc .= ""; for (;$cur_col < $columns;$cur_col++) $renderer->doc .= ""; } $renderer->doc .= "
"; $cur_col++; break; case 'break': if ($cur_col > 0) $renderer->doc .= "
"; $cur_col=1; break; case 'end_col': if ($cur_col > 0) { $renderer->doc .= "
"; $cur_col = 0; $clumns = 4; break; } } } else { $renderer->doc .= $renderer->_xmlEntities($data[1]); } } elseif ($format == 'metadata') { if ($renderer->capture) { if ($data[0] !== false) { if (in_array('open_col',$data) || in_array('col',$data) || in_array('break',$data)) { $renderer->doc .= DOKU_LF; } elseif (in_array('end_col',$data)) { if (strlen($renderer->doc) > 250) $renderer->capture = false; } else return false; } else { $renderer->doc .= $data[1]; } } return true; } return false; } }