Skip to content

Commit

Permalink
set syntax pattern in preConnect()
Browse files Browse the repository at this point in the history
  • Loading branch information
ssahara committed Oct 9, 2019
1 parent bcef5cc commit 8d4d084
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 47 deletions.
45 changes: 25 additions & 20 deletions syntax/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,29 @@

class syntax_plugin_typography_base extends DokuWiki_Syntax_Plugin
{
protected $pattern = array(
1 => '<typo\b.*?>(?=.*?</typo>)',
4 => '</typo>',
);

protected $mode;
protected $styler = null;

public function getType()
{ // Syntax Type
return 'formatting';
}

public function getSort()
{ // sort number used to determine priority of this mode
return 67; // = Doku_Parser_Mode_formatting:strong -3
}

public function getAllowedTypes()
{ // Allowed Mode Types
return array('formatting', 'substition', 'disabled');
}

// plugin accepts its own entry syntax
public function accepts($mode)
{
if ($mode == $this->mode) return true;
return parent::accepts($mode);
}

/**
* Connect pattern to lexer
*/
protected $mode, $pattern;

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

// syntax pattern
$this->pattern[1] = '<typo\b.*?>(?=.*?</typo>)';
$this->pattern[4] = '</typo>';
}

public function connectTo($mode)
Expand All @@ -61,6 +47,25 @@ public function postConnect()
$this->Lexer->addExitPattern($this->pattern[4], $this->mode);
}

public function getSort()
{ // sort number used to determine priority of this mode
return 67; // = Doku_Parser_Mode_formatting:strong -3
}

// plugin accepts its own entry syntax
public function accepts($mode)
{
if ($mode == $this->mode) return true;
return parent::accepts($mode);
}


/**
* Plugin features
*/
protected $styler = null;


/*
* Handle the match
*/
Expand Down
17 changes: 12 additions & 5 deletions syntax/fontcolor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@

class syntax_plugin_typography_fontcolor extends syntax_plugin_typography_base
{
protected $pattern = array(
1 => '<fc\b.*?>(?=.*?</fc>)',
4 => '</fc>',
);
/**
* Connect pattern to lexer
*/
public function preConnect()
{
// drop 'syntax_' from class name
$this->mode = substr(get_class($this), 7);

// syntax pattern
$this->pattern[1] = '<fc\b.*?>(?=.*?</fc>)';
$this->pattern[4] = '</fc>';
}

// Connect pattern to lexer
public function connectTo($mode)
{
if (plugin_isdisabled('fontcolor')) {
Expand Down
17 changes: 12 additions & 5 deletions syntax/fontfamily.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@

class syntax_plugin_typography_fontfamily extends syntax_plugin_typography_base
{
protected $pattern = array(
1 => '<ff\b.*?>(?=.*?</ff>)',
4 => '</ff>',
);
/**
* Connect pattern to lexer
*/
public function preConnect()
{
// drop 'syntax_' from class name
$this->mode = substr(get_class($this), 7);

// syntax pattern
$this->pattern[1] = '<ff\b.*?>(?=.*?</ff>)';
$this->pattern[4] = '</ff>';
}

// Connect pattern to lexer
public function connectTo($mode)
{
if (plugin_isdisabled('fontfamily')) {
Expand Down
17 changes: 12 additions & 5 deletions syntax/fontsize.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@

class syntax_plugin_typography_fontsize extends syntax_plugin_typography_base
{
protected $pattern = array(
1 => '<fs\b.*?>(?=.*?</fs>)',
4 => '</fs>',
);
/**
* Connect pattern to lexer
*/
public function preConnect()
{
// drop 'syntax_' from class name
$this->mode = substr(get_class($this), 7);

// syntax pattern
$this->pattern[1] = '<fs\b.*?>(?=.*?</fs>)';
$this->pattern[4] = '</fs>';
}

// Connect pattern to lexer
public function connectTo($mode)
{
if (plugin_isdisabled('fontsize2')) {
Expand Down
16 changes: 12 additions & 4 deletions syntax/fontweight.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@

class syntax_plugin_typography_fontweight extends syntax_plugin_typography_base
{
protected $pattern = array(
1 => '<fw\b.*?>(?=.*?</fw>)',
4 => '</fw>',
);
/**
* Connect pattern to lexer
*/
public function preConnect()
{
// drop 'syntax_' from class name
$this->mode = substr(get_class($this), 7);

// syntax pattern
$this->pattern[1] = '<fw\b.*?>(?=.*?</fw>)';
$this->pattern[4] = '</fw>';
}

}
16 changes: 12 additions & 4 deletions syntax/smallcaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@

class syntax_plugin_typography_smallcaps extends syntax_plugin_typography_base
{
protected $pattern = array(
1 => '<smallcaps\b.*?>(?=.*?</smallcaps>)',
4 => '</smallcaps>',
);
/**
* Connect pattern to lexer
*/
public function preConnect()
{
// drop 'syntax_' from class name
$this->mode = substr(get_class($this), 7);

// syntax pattern
$this->pattern[1] = '<smallcaps\b.*?>(?=.*?</smallcaps>)';
$this->pattern[4] = '</smallcaps>';
}

//protected $styler = null;

Expand Down
16 changes: 12 additions & 4 deletions syntax/webfont.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@

class syntax_plugin_typography_webfont extends syntax_plugin_typography_base
{
protected $pattern = array(
1 => '<wf\b.*?>(?=.*?</wf>)',
4 => '</wf>',
);
/**
* Connect pattern to lexer
*/
public function preConnect()
{
// drop 'syntax_' from class name
$this->mode = substr(get_class($this), 7);

// syntax pattern
$this->pattern[1] = '<wf\b.*?>(?=.*?</wf>)';
$this->pattern[4] = '</wf>';
}

}

0 comments on commit 8d4d084

Please sign in to comment.