Skip to content

Commit

Permalink
use \R for pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
ssahara committed Jul 20, 2018
1 parent 0b4eefa commit 6559c59
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
8 changes: 5 additions & 3 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class action_plugin_commentsyntax extends DokuWiki_Action_Plugin {
/**
* register the eventhandlers
*/
public function register(Doku_Event_Handler $controller){
function register(Doku_Event_Handler $controller) {
if ($this->getConf('toolbar_button')) {
$controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'handleToolbar');
$controller->register_hook(
'TOOLBAR_DEFINE', 'AFTER', $this, 'handleToolbar'
);
}
}

public function handleToolbar(Doku_Event $event, $param) {
function handleToolbar(Doku_Event $event) {
$event->data[] = array (
'type' => 'toggleCommentBlock',
'title' => $this->getLang('toolbar_title'),
Expand Down
19 changes: 10 additions & 9 deletions syntax/cstyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,46 @@ class syntax_plugin_commentsyntax_cstyle extends DokuWiki_Syntax_Plugin {
5 => '\s//(?:[^/\n]*|[^/\n]*/[^/\n]*)(?=\n)',
);

public function __construct() {
$this->mode = substr(get_class($this), 7); // drop 'syntax_'
function __construct() {
// syntax mode, drop 'syntax_' from class name
$this->mode = substr(get_class($this), 7);
}

public function getType(){ return 'protected'; }
public function getSort(){
function getType(){ return 'protected'; }
function getSort(){
return 8; // precedence of Doku_Parser_Mode_listblock priority (=10)
}

public function accepts($mode) {
function accepts($mode) {
if ($this->getConf('use_cstyle_nest') && $mode == $this->mode) return true;
return parent::accepts($mode);
}

/**
* Connect lookup pattern to lexer
*/
public function connectTo($mode) {
function connectTo($mode) {
$this->Lexer->addEntryPattern($this->pattern[1], $mode, $this->mode);

if ($this->getConf('use_oneline_style')) {
$this->Lexer->addSpecialPattern($this->pattern[5], $mode, $this->mode);
}
}
public function postConnect() {
function postConnect() {
$this->Lexer->addExitPattern($this->pattern[4], $this->mode);
}

/**
* Handle the match
*/
public function handle($match, $state, $pos, Doku_Handler $handler) {
function handle($match, $state, $pos, Doku_Handler $handler) {
return false;
}

/**
* Create output
*/
public function render($format, Doku_Renderer $renderer, $data) {
function render($format, Doku_Renderer $renderer, $data) {
return true;
}
}
37 changes: 21 additions & 16 deletions syntax/preventive.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,48 @@
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_commentsyntax_preventive extends DokuWiki_Syntax_Plugin {

protected $mode;
protected $pattern = array(
5 => '~~[^\r\n]+?~~',
5 => '~~[^\R~]+~~',
);

public function __construct() {
$this->mode = substr(get_class($this), 7); // drop 'syntax_'
function __construct() {
// syntax mode, drop 'syntax_' from class name
$this->mode = substr(get_class($this), 7);
}

public function getType(){ return 'substition'; }
public function getSort(){ return 9999; } // very low priority
function getType(){ return 'substition'; }
function getSort(){ return 9999; } // very low priority

public function connectTo($mode) {
/**
* Connect lookup pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern($this->pattern[5], $mode, $this->mode);
}

public function handle($match, $state, $pos, Doku_Handler $handler) {
/**
* Handle the match
*/
function handle($match, $state, $pos, Doku_Handler $handler) {
global $ID, $ACT;
if ($ACT == 'preview') {
return array($state, $match);
return $data = $match;
} else if ($this->getConf('log_invalid_macro')) {
error_log($this->mode.': match='.$match.' |'.$ID);
}
return '';
return false;
}

public function render($format, Doku_Renderer $renderer, $data) {
/**
* Create output
*/
function render($format, Doku_Renderer $renderer, $data) {
global $ACT;
if ($format == 'xhtml' && $ACT == 'preview') {
list($state, $match) = $data;
$renderer->doc .= $renderer->_xmlEntities($match);
$renderer->doc .= $renderer->_xmlEntities($data);
}
return true;
}
Expand Down

0 comments on commit 6559c59

Please sign in to comment.