diff options
author | Daniel Baumann <daniel@debian.org> | 2024-12-01 20:45:31 +0100 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-12-01 22:18:39 +0100 |
commit | 1ae6b3d4a2c6547d7582fab303e79fa8c4cd7632 (patch) | |
tree | 4e23c2ec77ad5d9f7cf3bb7cf9a2a26bf096878f /plugins/55/wrap/syntax/span.php | |
parent | Adding wrap makefile. (diff) | |
download | dokuwiki-plugins-extra-tmp-new-plugins.tar.xz dokuwiki-plugins-extra-tmp-new-plugins.zip |
Adding wrap version 2023-08-13 (63b6c01).tmp-new-plugins
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'plugins/55/wrap/syntax/span.php')
-rw-r--r-- | plugins/55/wrap/syntax/span.php | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/plugins/55/wrap/syntax/span.php b/plugins/55/wrap/syntax/span.php new file mode 100644 index 0000000..ac75713 --- /dev/null +++ b/plugins/55/wrap/syntax/span.php @@ -0,0 +1,100 @@ +<?php +/** + * Span Syntax Component of the Wrap Plugin + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Anika Henke <anika@selfthinker.org> + */ + +class syntax_plugin_wrap_span extends DokuWiki_Syntax_Plugin { + protected $special_pattern = '<span\b[^>\r\n]*?/>'; + protected $entry_pattern = '<span\b.*?>(?=.*?</span>)'; + protected $exit_pattern = '</span>'; + + function getType(){ return 'formatting';} + function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); } + function getPType(){ return 'normal';} + 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); + } + + /** + * Connect pattern to lexer + */ + function connectTo($mode) { + $this->Lexer->addSpecialPattern($this->special_pattern,$mode,'plugin_wrap_'.$this->getPluginComponent()); + $this->Lexer->addEntryPattern($this->entry_pattern,$mode,'plugin_wrap_'.$this->getPluginComponent()); + } + + function postConnect() { + $this->Lexer->addExitPattern($this->exit_pattern, 'plugin_wrap_'.$this->getPluginComponent()); + } + + /** + * Handle the match + */ + function handle($match, $state, $pos, Doku_Handler $handler){ + switch ($state) { + case DOKU_LEXER_ENTER: + case DOKU_LEXER_SPECIAL: + $data = strtolower(trim(substr($match,strpos($match,' '),-1)," \t\n/")); + return array($state, $data); + + case DOKU_LEXER_UNMATCHED : + $handler->addCall('cdata', array($match), $pos); + return false; + + case DOKU_LEXER_EXIT : + return array($state, ''); + + } + return false; + } + + /** + * Create output + */ + function render($format, Doku_Renderer $renderer, $indata) { + static $type_stack = array (); + + if (empty($indata)) return false; + list($state, $data) = $indata; + + if($format == 'xhtml'){ + switch ($state) { + case DOKU_LEXER_ENTER: + case DOKU_LEXER_SPECIAL: + $wrap = $this->loadHelper('wrap'); + $attr = $wrap->buildAttributes($data); + + $renderer->doc .= '<span'.$attr.'>'; + if ($state == DOKU_LEXER_SPECIAL) $renderer->doc .= '</span>'; + break; + + case DOKU_LEXER_EXIT: + $renderer->doc .= '</span>'; + break; + } + return true; + } + if($format == 'odt'){ + switch ($state) { + case DOKU_LEXER_ENTER: + $wrap = plugin_load('helper', 'wrap'); + array_push ($type_stack, $wrap->renderODTElementOpen($renderer, 'span', $data)); + break; + + case DOKU_LEXER_EXIT: + $element = array_pop ($type_stack); + $wrap = plugin_load('helper', 'wrap'); + $wrap->renderODTElementClose ($renderer, $element); + break; + } + return true; + } + return false; + } +} |