5 * Parses for text marked as revised (insert/delete).
11 * @author Paul M. Jones <pmjones@php.net>
15 * @version $Id: Revise.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
21 * Parses for text marked as revised (insert/delete).
27 * @author Paul M. Jones <pmjones@php.net>
31 class Text_Wiki_Parse_Revise
extends Text_Wiki_Parse
{
36 * The regular expression used to parse the source text and find
37 * matches conforming to this rule. Used by the parse() method.
47 var $regex = "/\@\@({*?.*}*?)\@\@/U";
68 * Generates a replacement for the matched text. Token options are:
70 * 'type' => ['start'|'end'] The starting or ending point of the
71 * inserted text. The text itself is left in the source.
75 * @param array &$matches The array of matches from parse().
77 * @return string A pair of delimited tokens to be used as a
78 * placeholder in the source text surrounding the teletype text.
82 function process(&$matches)
86 $delmark = $this->getConf('delmark'); // ---
87 $insmark = $this->getConf('insmark'); // +++
89 // '---' must be before '+++' (if they both appear)
90 $del = strpos($src, $delmark);
91 $ins = strpos($src, $insmark);
93 // if neither is found, return right away
94 if ($del === false
&& $ins === false
) {
98 // handle text to be deleted
101 // move forward to the end of the deletion mark
102 $del +
= strlen($delmark);
104 if ($ins === false
) {
105 // there is no insertion text following
106 $text = substr($src, $del);
108 // there is insertion text following,
109 // mitigate the length
110 $text = substr($src, $del, $ins - $del);
113 $output .= $this->wiki
->addToken(
114 $this->rule
, array('type' => 'del_start')
119 $output .= $this->wiki
->addToken(
120 $this->rule
, array('type' => 'del_end')
124 // handle text to be inserted
125 if ($ins !== false
) {
127 // move forward to the end of the insert mark
128 $ins +
= strlen($insmark);
129 $text = substr($src, $ins);
131 $output .= $this->wiki
->addToken(
132 $this->rule
, array('type' => 'ins_start')
137 $output .= $this->wiki
->addToken(
138 $this->rule
, array('type' => 'ins_end')