1<?php 2// must be run within Dokuwiki 3if(!defined('DOKU_INC')) die(); 4 5require_once(DOKU_PLUGIN.'formatplus/formatting.php'); 6 7class syntax_plugin_formatplus_quoteplus extends FormattingPlus_Syntax_Plugin { 8 9 var $disabled = false; 10 11 function _getName() { 12 return 'Quote+'; 13 } 14 function _getDesc() { 15 return 'Create inline quote with optional citation. '. 16 'Syntax: ""Inline Quote"" ""=cite|With citation""'; 17 } 18 function _getConfig() { 19 return 'quote'; 20 } 21 22 function _getFormatting() { 23 return array(); 24 } 25 26 function getSort() { 27 return 107; 28 } 29 30 function getAllowedTypes() { 31 return array('formatting','substition','disabled'); 32 } 33 34 function preConnect() { 35 if ($this->_disabledSyntax($this->_getConfig())) 36 $this->disabled = true; 37 } 38 39 function connectTo($mode) { 40 if (!$this->disabled) { 41 $this->Lexer->addEntryPattern('\x22\x22=[^\x22\r\n]+?\|(?=.*\x22\x22)', $mode, 'plugin_formatplus_quoteplus'); 42 $this->Lexer->addEntryPattern('\x22\x22(?=.*\x22\x22)', $mode, 'plugin_formatplus_quoteplus'); 43 } 44 } 45 46 function postConnect() { 47 if (!$this->disabled) { 48 $this->Lexer->addExitPattern('\x22\x22', 'plugin_formatplus_quoteplus'); 49 } 50 } 51 52 function handle($match, $state, $pos, &$handler){ 53 switch ($state) { 54 case DOKU_LEXER_ENTER: 55 if (substr($match,2,1) == '=') 56 $output = substr($match,3,-1); 57 else 58 $output = ''; 59 break; 60 case DOKU_LEXER_EXIT: 61 $output = ''; 62 break; 63 case DOKU_LEXER_UNMATCHED: 64 $output = $match; 65 break; 66 } 67 return array($state,$output); 68 } 69 70 function render($format, &$renderer, $data) { 71 list($state,$output) = $data; 72 if ($format == 'xhtml'){ 73 switch ($state) { 74 case DOKU_LEXER_ENTER: 75 if (!empty($output)) { 76 $renderer->doc .= '<q cite="'.$renderer->_xmlEntities($output).'">'; 77 } else { 78 $renderer->doc .= '<q>'; 79 } 80 break; 81 case DOKU_LEXER_EXIT: 82 $renderer->doc .= '</q>'; 83 break; 84 case DOKU_LEXER_UNMATCHED: 85 $renderer->doc .= $renderer->_xmlEntities($output); 86 break; 87 } 88 return true; 89 } elseif ($format == 'metadata') { 90 switch ($state) { 91 case DOKU_LEXER_ENTER: 92 if ($renderer->capture){ 93 $renderer->doc .= DOKU_LF; 94 if(!empty($output)){ 95 $renderer->doc .= $output.':'; 96 } 97 } 98 break; 99 case DOKU_LEXER_EXIT: 100 if ($renderer->capture) { 101 $renderer->doc .= DOKU_LF; 102 if (strlen($renderer->doc) > 250) $renderer->capture = false; 103 } 104 break; 105 case DOKU_LEXER_UNMATCHED: 106 if ($renderer->capture) $renderer->doc .= $output; 107 break; 108 } 109 return true; 110 } 111 return false; 112 } 113} 114