This is my centered note * This is my left sided note * This is my right sided note * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Stephane Chamberland */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_sidenote extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Stephane Chamberland', 'email' => 'stephane.chamberland@ec.gc.ca', 'date' => '2005-07-04', 'name' => 'Side Note/Float Box Plugin', 'desc' => 'Add Side Note Capability (CSS Float box)', 'url' => 'http://www.dokuwiki.org/plugin:side_note', ); } /** * Constructor - adds allowed modes */ function syntax_plugin_sidenote(){ global $PARSER_MODES; $this->allowedModes = array_merge( $PARSER_MODES['formatting'], $PARSER_MODES['substition'], $PARSER_MODES['disabled'] ); } /** * What kind of syntax are we? */ function getType(){ //return 'container'; return 'formatting'; } /** * Paragraph Type * * Defines how this syntax is handled regarding paragraphs. This is important * for correct XHTML nesting. Should return one of the following: * * 'normal' - The plugin can be used inside paragraphs * 'block' - Open paragraphs need to be closed before plugin output * 'stack' - Special case. Plugin wraps other paragraphs. * * @see Doku_Handler_Block */ function getPType(){ return 'stack'; } /** * Where to sort in? */ function getSort(){ return 155; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addEntryPattern('(?=.*)',$mode,'plugin_sidenote'); $this->Lexer->addEntryPattern('(?=.*)',$mode,'plugin_sidenote'); $this->Lexer->addEntryPattern('(?=.*)',$mode,'plugin_sidenote'); } function postConnect() { $this->Lexer->addExitPattern('','plugin_sidenote'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ switch ( $state ) { case DOKU_LEXER_ENTER: if (preg_match('/left>/', $match)>0) { return array('',$state,'left'); } else if (preg_match('/right>/', $match)>0) { return array('',$state,'right'); } else { return array('',$state,''); } break; case DOKU_LEXER_UNMATCHED: //$matches = preg_split('/>/u',$match,2); //$matches[0] = trim($matches[0]); //$matches[1] = trim(implode('>',array_slice($matches,1))); //return array($matches[1], $state,$matches[0]); return array($match,$state,''); break; } return array('',$state,''); } /** * Create output */ function render($mode, &$renderer, $data) { if($mode == 'xhtml'){ if ($data[1] == DOKU_LEXER_ENTER){ if ($data[2] == 'right' ) { $renderer->doc .= ''; } else if ($data[2] == 'left') { $renderer->doc .= ''; } else { $renderer->doc .= ''; } } else if ($data[1] == DOKU_LEXER_UNMATCHED){ $renderer->doc .= $data[0]; } else if ($data[1] == DOKU_LEXER_EXIT){ $renderer->doc .= ''; } return true; } return false; if($mode == 'xhtml' && strlen($data[0]) > 1) { return true; } return false; } } //Setup VIM: ex: et ts=4 enc=utf-8 : ?>