132 if ( !preg_match( $this->regex, $marker, $m ) ) {
133 throw new InvalidArgumentException(
"Invalid marker: $marker" );
136 $this->data[$type][$m[1]] = $value;
138 $this->extra[$type][$m[1]] =
$extra;
166 if ( !count( $this->data[
'nowiki'] ) ) {
170 $callback =
function ( $m ) use ( $callback ) {
172 if ( isset( $this->data[
'nowiki'][$marker] ) ) {
173 $value = $this->data[
'nowiki'][$marker];
174 if ( $value instanceof Closure ) {
178 $this->expandSize += strlen( $value );
179 if ( $this->expandSize > $this->sizeLimit ) {
180 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
183 return $callback( $value );
189 return preg_replace_callback( $this->regex, $callback, $text );
200 public function split(
string $text ): array {
202 $pieces = preg_split( $this->regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
203 for ( $i = 0; $i < count( $pieces ); $i++ ) {
204 if ( $i % 2 === 0 ) {
207 'content' => $pieces[$i],
211 $marker = $pieces[$i];
212 foreach ( $this->data as $type => $items ) {
213 if ( isset( $items[$marker] ) ) {
214 $value = $items[$marker];
215 $extra = $this->extra[$type][$marker] ??
null;
216 if ( $value instanceof Closure ) {
220 if ( $type ===
'exttag' ) {
223 if ( isset( $this->circularRefGuard[$marker] ) ) {
226 'content' => $this->getWarning(
'parser-unstrip-loop-warning' )
231 if ( $this->depth > $this->highestDepth ) {
232 $this->highestDepth = $this->depth;
234 if ( $this->depth >= $this->depthLimit ) {
237 'content' => $this->getLimitationWarning(
'unstrip-depth', $this->depthLimit )
246 $this->expandSize += strlen( $value );
247 if ( $this->expandSize > $this->sizeLimit ) {
250 'content' => $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit )
255 $this->circularRefGuard[$marker] =
true;
257 $result = array_merge( $result, $this->split( $value ) );
259 unset( $this->circularRefGuard[$marker] );
297 if ( !count( $this->data[$type] ) ) {
301 $callback =
function ( $m ) use ( $type ) {
303 if ( isset( $this->data[$type][$marker] ) ) {
304 if ( isset( $this->circularRefGuard[$marker] ) ) {
305 return $this->getWarning(
'parser-unstrip-loop-warning' );
308 if ( $this->depth > $this->highestDepth ) {
309 $this->highestDepth = $this->depth;
311 if ( $this->depth >= $this->depthLimit ) {
312 return $this->getLimitationWarning(
'unstrip-depth', $this->depthLimit );
315 $value = $this->data[$type][$marker];
316 if ( $value instanceof Closure ) {
320 $this->expandSize += strlen( $value );
321 if ( $this->expandSize > $this->sizeLimit ) {
322 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
325 $this->circularRefGuard[$marker] =
true;
327 $ret = $this->unstripType( $type, $value );
329 unset( $this->circularRefGuard[$marker] );
337 $text = preg_replace_callback( $this->regex, $callback, $text );