118 if ( !preg_match( $this->regex, $marker, $m ) ) {
119 throw new InvalidArgumentException(
"Invalid marker: $marker" );
122 $this->data[$type][$m[1]] = $value;
124 $this->extra[$type][$m[1]] =
$extra;
152 if ( !count( $this->data[
'nowiki'] ) ) {
156 $callback =
function ( $m ) use ( $callback ) {
158 if ( isset( $this->data[
'nowiki'][$marker] ) ) {
159 $value = $this->data[
'nowiki'][$marker];
160 if ( $value instanceof Closure ) {
164 $this->expandSize += strlen( $value );
165 if ( $this->expandSize > $this->sizeLimit ) {
166 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
169 return $callback( $value );
175 return preg_replace_callback( $this->regex, $callback, $text );
186 public function split(
string $text ): array {
188 $pieces = preg_split( $this->regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
189 for ( $i = 0; $i < count( $pieces ); $i++ ) {
190 if ( $i % 2 === 0 ) {
193 'content' => $pieces[$i],
197 $marker = $pieces[$i];
198 foreach ( $this->data as $type => $items ) {
199 if ( isset( $items[$marker] ) ) {
200 $value = $items[$marker];
201 $extra = $this->extra[$type][$marker] ??
null;
202 if ( $value instanceof Closure ) {
206 if ( $type ===
'exttag' ) {
209 if ( isset( $this->circularRefGuard[$marker] ) ) {
212 'content' => $this->getWarning(
'parser-unstrip-loop-warning' )
217 if ( $this->depth > $this->highestDepth ) {
218 $this->highestDepth = $this->depth;
220 if ( $this->depth >= $this->depthLimit ) {
223 'content' => $this->getLimitationWarning(
'unstrip-depth', $this->depthLimit )
232 $this->expandSize += strlen( $value );
233 if ( $this->expandSize > $this->sizeLimit ) {
236 'content' => $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit )
241 $this->circularRefGuard[$marker] =
true;
243 $result = array_merge( $result, $this->split( $value ) );
245 unset( $this->circularRefGuard[$marker] );
283 if ( !count( $this->data[$type] ) ) {
287 $callback =
function ( $m ) use ( $type ) {
289 if ( isset( $this->data[$type][$marker] ) ) {
290 if ( isset( $this->circularRefGuard[$marker] ) ) {
291 return $this->getWarning(
'parser-unstrip-loop-warning' );
294 if ( $this->depth > $this->highestDepth ) {
295 $this->highestDepth = $this->depth;
297 if ( $this->depth >= $this->depthLimit ) {
298 return $this->getLimitationWarning(
'unstrip-depth', $this->depthLimit );
301 $value = $this->data[$type][$marker];
302 if ( $value instanceof Closure ) {
306 $this->expandSize += strlen( $value );
307 if ( $this->expandSize > $this->sizeLimit ) {
308 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
311 $this->circularRefGuard[$marker] =
true;
313 $ret = $this->unstripType( $type, $value );
315 unset( $this->circularRefGuard[$marker] );
323 $text = preg_replace_callback( $this->regex, $callback, $text );