From 68656728cf13ee1317e9082ae3705ca7bb7a1392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ctibor=20Bran=C4=8D=C3=ADk?= Date: Wed, 23 Mar 2016 20:43:48 +0100 Subject: Add imagebox and note plugins. --- lib/plugins/note/syntax.php | 191 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 lib/plugins/note/syntax.php (limited to 'lib/plugins/note/syntax.php') diff --git a/lib/plugins/note/syntax.php b/lib/plugins/note/syntax.php new file mode 100644 index 000000000..368d0d412 --- /dev/null +++ b/lib/plugins/note/syntax.php @@ -0,0 +1,191 @@ +This is note + * This is note + * This is an important note + * This is a big warning + * This is a tip + * + * by Olivier Cortès + * under the terms of the GNU GPL v2. + * + * Originaly derived from the work of : + * Stephane Chamberland (Side Notes PlugIn) + * Carl-Christian Salvesen (Graphviz plugin) + * + * Contributions by Eric Hameleers : + * use
instead of , + * contain the images and stylesheet inside the plugin, + * permit nesting of notes, + * + * Contributed by Christopher Smith + * fix some parsing problems and a security hole. + * make note types case independent + * simplify code reading + * modernise the plugin for changes/fixes/improvements to the underlying Dokuwiki plugin class, + * improve efficiency. + * + * Contributed by Aurélien Bompard + * support for the ODT output format. + * + * @license GNU_GPL_v2 + * @author Olivier Cortes + */ + +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'); + + +class syntax_plugin_note extends DokuWiki_Syntax_Plugin { + + var $notes = array( + 'noteimportant' => array('important', 'importante'), + 'notewarning' => array('warning','bloquante','critique'), + 'notetip' => array('tip','tuyau','idée'), + 'noteclassic' => array('','classic','classique') + ); + + var $default = 'noteclassic'; + + function getInfo(){ + return confToHash(dirname(__FILE__).'/info.txt'); + } + + + function getType(){ return 'container'; } + function getPType(){ return 'normal'; } + function getAllowedTypes() { + return array('container','substition','protected','disabled','formatting','paragraphs'); + } + function getSort(){ return 195; } + + // override default accepts() method to allow nesting + // - ie, to get the plugin accepts its own entry syntax + function accepts($mode) { + if ($mode == substr(get_class($this), 7)) return true; + return parent::accepts($mode); + } + + function connectTo($mode) { + $this->Lexer->addEntryPattern('(?=.*?)',$mode,'plugin_note'); + } + function postConnect() { + $this->Lexer->addExitPattern('','plugin_note'); + } + + function handle($match, $state, $pos, &$handler){ + + switch ($state) { + + case DOKU_LEXER_ENTER : + $note = strtolower(trim(substr($match,5,-1))); + + foreach( $this->notes as $class => $names ) { + if (in_array($note, $names)) + return array($state, $class); + } + + return array($state, $this->default); + + case DOKU_LEXER_UNMATCHED : + return array($state, $match); + + default: + return array($state); + } + } + + function render($mode, &$renderer, $indata) { + + if($mode == 'xhtml'){ + + list($state, $data) = $indata; + + switch ($state) { + case DOKU_LEXER_ENTER : + $renderer->doc .= '

'; + break; + + case DOKU_LEXER_UNMATCHED : + $renderer->doc .= $renderer->_xmlEntities($data); + break; + + case DOKU_LEXER_EXIT : + $renderer->doc .= "\n

"; + break; + } + return true; + + } elseif ($mode == 'odt'){ + + list($state, $data) = $indata; + + switch ($state) { + case DOKU_LEXER_ENTER : + $type = substr($data, 4); + if ($type == "classic") { + $type = "note"; // the icon for classic notes is named note.png + } + $colors = array("note"=>"#eeffff", "warning"=>"#ffdddd", "important"=>"#ffffcc", "tip"=>"#ddffdd"); + $renderer->autostyles["pluginnote"] = ' + + + '; + $renderer->autostyles["pluginnote.A"] = ' + + + '; + $renderer->autostyles["pluginnote.B"] = ' + + + '; + $renderer->autostyles["pluginnote".$type.".A1"] = ' + + + '; + $renderer->autostyles["pluginnote".$type.".B1"] = ' + + + '; + // Content + $renderer->p_close(); + $renderer->doc .= ''; + $renderer->doc .= ''; + $renderer->doc .= ''; + $renderer->doc .= ''; + $renderer->doc .= ''; + // Don't use p_open, as it's not the same style-name + $renderer->doc .= ''; + $src = DOKU_PLUGIN."note/images/".$type.".png"; + $renderer->_odtAddImage($src); + $renderer->doc .= ''; + $renderer->doc .= ''; + $renderer->doc .= ''; + $renderer->p_open(); + break; + + case DOKU_LEXER_UNMATCHED : + $renderer->cdata($data); + break; + + case DOKU_LEXER_EXIT : + $renderer->p_close(); + $renderer->doc .= ''; + $renderer->doc .= ''; + $renderer->doc .= ''; + $renderer->p_open(); + break; + } + return true; + } + + // unsupported $mode + return false; + } +} + +//Setup VIM: ex: et ts=4 enc=utf-8 : +?> -- cgit v1.2.3