You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

101 lines
3.3 KiB

  1. <?php
  2. /**
  3. * Span Syntax Component of the Wrap Plugin
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Anika Henke <anika@selfthinker.org>
  7. */
  8. class syntax_plugin_wrap_span extends DokuWiki_Syntax_Plugin {
  9. protected $special_pattern = '<span\b[^>\r\n]*?/>';
  10. protected $entry_pattern = '<span\b.*?>(?=.*?</span>)';
  11. protected $exit_pattern = '</span>';
  12. function getType(){ return 'formatting';}
  13. function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
  14. function getPType(){ return 'normal';}
  15. function getSort(){ return 195; }
  16. // override default accepts() method to allow nesting - ie, to get the plugin accepts its own entry syntax
  17. function accepts($mode) {
  18. if ($mode == substr(get_class($this), 7)) return true;
  19. return parent::accepts($mode);
  20. }
  21. /**
  22. * Connect pattern to lexer
  23. */
  24. function connectTo($mode) {
  25. $this->Lexer->addSpecialPattern($this->special_pattern,$mode,'plugin_wrap_'.$this->getPluginComponent());
  26. $this->Lexer->addEntryPattern($this->entry_pattern,$mode,'plugin_wrap_'.$this->getPluginComponent());
  27. }
  28. function postConnect() {
  29. $this->Lexer->addExitPattern($this->exit_pattern, 'plugin_wrap_'.$this->getPluginComponent());
  30. }
  31. /**
  32. * Handle the match
  33. */
  34. function handle($match, $state, $pos, Doku_Handler $handler){
  35. switch ($state) {
  36. case DOKU_LEXER_ENTER:
  37. case DOKU_LEXER_SPECIAL:
  38. $data = strtolower(trim(substr($match,strpos($match,' '),-1)," \t\n/"));
  39. return array($state, $data);
  40. case DOKU_LEXER_UNMATCHED :
  41. $handler->addCall('cdata', array($match), $pos);
  42. return false;
  43. case DOKU_LEXER_EXIT :
  44. return array($state, '');
  45. }
  46. return false;
  47. }
  48. /**
  49. * Create output
  50. */
  51. function render($format, Doku_Renderer $renderer, $indata) {
  52. static $type_stack = array ();
  53. if (empty($indata)) return false;
  54. list($state, $data) = $indata;
  55. if($format == 'xhtml'){
  56. switch ($state) {
  57. case DOKU_LEXER_ENTER:
  58. case DOKU_LEXER_SPECIAL:
  59. $wrap = $this->loadHelper('wrap');
  60. $attr = $wrap->buildAttributes($data);
  61. $renderer->doc .= '<span'.$attr.'>';
  62. if ($state == DOKU_LEXER_SPECIAL) $renderer->doc .= '</span>';
  63. break;
  64. case DOKU_LEXER_EXIT:
  65. $renderer->doc .= '</span>';
  66. break;
  67. }
  68. return true;
  69. }
  70. if($format == 'odt'){
  71. switch ($state) {
  72. case DOKU_LEXER_ENTER:
  73. $wrap = plugin_load('helper', 'wrap');
  74. array_push ($type_stack, $wrap->renderODTElementOpen($renderer, 'span', $data));
  75. break;
  76. case DOKU_LEXER_EXIT:
  77. $element = array_pop ($type_stack);
  78. $wrap = plugin_load('helper', 'wrap');
  79. $wrap->renderODTElementClose ($renderer, $element);
  80. break;
  81. }
  82. return true;
  83. }
  84. return false;
  85. }
  86. }