Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * DokuWiki Plugin telegramiv (Syntax Component)
  5. *
  6. * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
  7. * @author denko <denko@techie.com>
  8. */
  9.  
  10. // must be run within Dokuwiki
  11. if (!defined('DOKU_INC')) {
  12. die();
  13. }
  14.  
  15. class syntax_plugin_telegramiv_cover extends DokuWiki_Syntax_Plugin
  16. {
  17. /**
  18. * @return string Syntax mode type
  19. */
  20. public function getType()
  21. {
  22. return 'protected';
  23. }
  24.  
  25. /**
  26. * @return string Paragraph type
  27. */
  28. public function getPType()
  29. {
  30. return 'block';
  31. }
  32.  
  33. /**
  34. * @return int Sort order - Low numbers go before high numbers
  35. */
  36. public function getSort()
  37. {
  38. return 51;
  39. }
  40.  
  41. /**
  42. * Connect lookup pattern to lexer.
  43. *
  44. * @param string $mode Parser modes
  45. */
  46. public function connectTo($mode)
  47. {
  48. $this->Lexer->addSpecialPattern('<cover.*?>(?=.*?</cover>)', $mode, 'plugin_telegramiv_cover');
  49. // $this->Lexer->addEntryPattern('<FIXME>', $mode, 'plugin_telegramiv_cover');
  50. }
  51.  
  52. public function postConnect()
  53. {
  54. $this->Lexer->addExitPattern('</cover>', 'plugin_telegramiv_cover');
  55. }
  56.  
  57. /**
  58. * Handle matches of the telegramiv 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.  
  71. case DOKU_LEXER_ENTER:
  72. return array($state, $this->default);
  73.  
  74. case DOKU_LEXER_UNMATCHED:
  75. return array($state, $match);
  76.  
  77. default:
  78. return array($state);
  79. }
  80. }
  81.  
  82. /**
  83. * Render xhtml output or metadata
  84. *
  85. * @param string $mode Renderer mode (supported modes: xhtml)
  86. * @param Doku_Renderer $renderer The renderer
  87. * @param array $data The data from the handler() function
  88. *
  89. * @return bool If rendering was successful.
  90. */
  91. public function render($mode, Doku_Renderer $renderer, $indata)
  92. {
  93. if ($mode == 'xhtml') {
  94.  
  95. list($state, $data) = $indata;
  96.  
  97. switch ($state) {
  98. case DOKU_LEXER_ENTER :
  99. $renderer->doc .= '<h1>';
  100. break;
  101.  
  102. case DOKU_LEXER_UNMATCHED :
  103. $renderer->doc .= $data;
  104. break;
  105.  
  106. case DOKU_LEXER_EXIT :
  107. $renderer->doc .= "</h1>";
  108. break;
  109. }
  110. return true;
  111. }
  112.  
  113. return false;
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement