1<?php 2/** 3 * DokuWiki Plugin mark2memorize (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author shimamu <cooklecurry@gmail.com> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) { 11 die(); 12} 13 14class syntax_plugin_mark2memorize extends DokuWiki_Syntax_Plugin 15{ 16 /** 17 * @return string Syntax mode type 18 */ 19 public function getType() 20 { 21 return 'formatting'; 22 } 23 24 /** 25 * @return string Paragraph type 26 */ 27 public function getPType() 28 { 29 return 'normal'; 30 } 31 32 function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); } 33 34 /** 35 * @return int Sort order - Low numbers go before high numbers 36 */ 37 public function getSort() 38 { 39 return 100; 40 } 41 42 /** 43 * Connect lookup pattern to lexer. 44 * 45 * @param string $mode Parser mode 46 */ 47 public function connectTo($mode) 48 { 49 $this->Lexer->addEntryPattern('<markmemo.*?>(?=.*?</markmemo>)', $mode, 'plugin_mark2memorize'); 50 } 51 52 public function postConnect() 53 { 54 $this->Lexer->addExitPattern('</markmemo>', 'plugin_mark2memorize'); 55 } 56 57 /** 58 * Handle matches of the mark2memorize syntax 59 * 60 * @param string $match The match of the syntax 61 * @param int $state The state of the handler 62 * @param int $pos The position in the document 63 * @param Doku_Handler $handler The handler 64 * 65 * @return array Data for the renderer 66 */ 67 public function handle($match, $state, $pos, Doku_Handler $handler) 68 { 69 switch ($state) { 70 case DOKU_LEXER_ENTER : return array($state, ''); 71 case DOKU_LEXER_UNMATCHED : return array($state, $match); 72 case DOKU_LEXER_EXIT : return array($state, ''); 73 } 74 return array(); 75 } 76 77 /** 78 * Render xhtml output or metadata 79 * 80 * @param string $mode Renderer mode (supported modes: xhtml) 81 * @param Doku_Renderer $renderer The renderer 82 * @param array $data The data from the handler() function 83 * 84 * @return bool If rendering was successful. 85 */ 86 public function render($mode, Doku_Renderer $renderer, $data) 87 { 88 if ($mode == 'xhtml') { 89 list($state, $match) = $data; 90 switch ($state) { 91 case DOKU_LEXER_ENTER : 92 $renderer->doc .= "<span class='hide' onclick='showAnswer(this);'>"; 93 break; 94 case DOKU_LEXER_UNMATCHED : $renderer->doc .= $renderer->_xmlEntities($match); break; 95 case DOKU_LEXER_EXIT : $renderer->doc .= "</span>"; break; 96 } 97 return true; 98 } 99 return false; 100 } 101} 102?> 103