Skip to content

Commit

Permalink
Parser::doSpecial() uses named sub-patterns.
Browse files Browse the repository at this point in the history
See #121
  • Loading branch information
Jukka Svahn committed Oct 31, 2013
1 parent e43ba78 commit 7f6a057
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/Netcarver/Textile/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2998,8 +2998,7 @@ protected function code($text)

protected function fCode($m)
{
list(, $before, $text, $after) = array_pad($m, 4, '');
return $before.$this->shelve('<code>'.$this->rEncodeHTML($text).'</code>').$after;
return $m['before'].$this->shelve('<code>'.$this->rEncodeHTML($m['content']).'</code>').$m['after'];
}

/**
Expand All @@ -3011,8 +3010,7 @@ protected function fCode($m)

protected function fPre($m)
{
list(, $before, $text, $after) = array_pad($m, 4, '');
return $before.'<pre>'.$this->shelve($this->rEncodeHTML($text)).'</pre>'.$after;
return $m['before'].'<pre>'.$this->shelve($this->rEncodeHTML($m['content'])).'</pre>'.$m['after'];
}

/**
Expand Down Expand Up @@ -3088,7 +3086,7 @@ protected function cleanWhiteSpace($text)

protected function doSpecial($text, $start, $end, $method = 'fSpecial')
{
return preg_replace_callback('/(^|\s|[|[({>])'.preg_quote($start, '/').'(.*?)'.preg_quote($end, '/').'(\s|$|[\])}|])?/ms', array(&$this, $method), $text);
return preg_replace_callback('/(?P<before>^|\s|[|[({>])'.preg_quote($start, '/').'(?P<content>.*?)'.preg_quote($end, '/').'(?P<after>\s|$|[\])}|])?/ms', array(&$this, $method), $text);
}

/**
Expand All @@ -3104,9 +3102,7 @@ protected function doSpecial($text, $start, $end, $method = 'fSpecial')

protected function fSpecial($m)
{
// A special block like notextile or code
list(, $before, $text, $after) = array_pad($m, 4, '');
return $before.$this->shelve($this->encodeHTML($text)).$after;
return $m['before'].$this->shelve($this->encodeHTML($m['content'])).$m['after'];
}

/**
Expand All @@ -3131,8 +3127,7 @@ protected function noTextile($text)

protected function fTextile($m)
{
list(, $before, $notextile, $after) = array_pad($m, 4, '');
return $before.$this->shelve($notextile).$after;
return $m['before'].$this->shelve($m['content']).$m['after'];
}

/**
Expand Down

0 comments on commit 7f6a057

Please sign in to comment.