cstyle.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Comment Syntax plugin for DokuWiki; cstyle syntax component
  4. *
  5. * A "comment" does not appear in the page, but visible when you edit the page.
  6. * Supports both C style multi-line comments and one-line C++ style comments
  7. *
  8. * NOTE:
  9. * One-line comments preceded by two slashes (//), may interfere with the markup
  10. * for italics. The use of italic formatting markup will be restricted so that
  11. * it can not go over next line.
  12. *
  13. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  14. * @author Satoshi Sahara <sahara.satoshi@gmail.com>
  15. */
  16. class syntax_plugin_commentsyntax_cstyle extends DokuWiki_Syntax_Plugin
  17. {
  18. /** syntax type */
  19. public function getType()
  20. {
  21. return 'protected';
  22. }
  23. /** sort number used to determine priority of this mode */
  24. public function getSort()
  25. {
  26. return 8; // precedence of Doku_Parser_Mode_listblock priority (=10)
  27. }
  28. /**
  29. * Connect lookup pattern to lexer
  30. */
  31. protected $mode, $pattern;
  32. public function preConnect()
  33. {
  34. // syntax mode, drop 'syntax_' from class name
  35. $this->mode = substr(__CLASS__, 7);
  36. // syntax pattern
  37. $this->pattern = [
  38. 1 => '[ \t]*\n?/\*(?=.*?\*/)',
  39. 4 => '\*/',
  40. 5 => '\s//(?:[^/\n]*|[^/\n]*/[^/\n]*)(?=\n)',
  41. ];
  42. }
  43. public function accepts($mode)
  44. { // plugin may accept its own entry syntax
  45. if ($this->getConf('use_cstyle_nest') && $mode == $this->mode) return true;
  46. return parent::accepts($mode);
  47. }
  48. public function connectTo($mode)
  49. {
  50. $this->Lexer->addEntryPattern($this->pattern[1], $mode, $this->mode);
  51. if ($this->getConf('use_oneline_style')) {
  52. $this->Lexer->addSpecialPattern($this->pattern[5], $mode, $this->mode);
  53. }
  54. }
  55. public function postConnect()
  56. {
  57. $this->Lexer->addExitPattern($this->pattern[4], $this->mode);
  58. }
  59. /**
  60. * Handle the match
  61. */
  62. public function handle($match, $state, $pos, Doku_Handler $handler)
  63. {
  64. return false;
  65. }
  66. /**
  67. * Create output
  68. */
  69. public function render($format, Doku_Renderer $renderer, $data)
  70. {
  71. return true;
  72. }
  73. }