119 if ( !preg_match( $this->regex, $marker, $m ) ) {
120 throw new InvalidArgumentException(
"Invalid marker: $marker" );
123 $this->data[$type][$m[1]] = $value;
125 $this->extra[$type][$m[1]] =
$extra;
153 if ( !count( $this->data[
'nowiki'] ) ) {
157 $callback =
function ( $m ) use ( $callback ) {
159 if ( isset( $this->data[
'nowiki'][$marker] ) ) {
160 $value = $this->data[
'nowiki'][$marker];
161 if ( $value instanceof Closure ) {
165 $this->expandSize += strlen( $value );
166 if ( $this->expandSize > $this->sizeLimit ) {
167 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
170 $extra = $this->extra[
'nowiki'][$marker] ??
null;
171 return $callback( $value,
$extra );
177 return preg_replace_callback( $this->regex, $callback, $text );
188 public function split(
string $text,
bool $keepExtTag =
false ): array {
190 $pieces = preg_split( $this->regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
191 for ( $i = 0; $i < count( $pieces ); $i++ ) {
192 if ( $i % 2 === 0 ) {
195 'content' => $pieces[$i],
199 $marker = $pieces[$i];
200 foreach ( $this->data as $type => $items ) {
201 if ( isset( $items[$marker] ) ) {
202 $value = $items[$marker];
203 $extra = $this->extra[$type][$marker] ??
null;
204 if ( $value instanceof Closure ) {
208 if ( $type ===
'exttag' ) {
211 if ( isset( $this->circularRefGuard[$marker] ) ) {
214 'content' => $this->getWarning(
'parser-unstrip-loop-warning' )
219 if ( $this->depth > $this->highestDepth ) {
220 $this->highestDepth = $this->depth;
222 if ( $this->depth >= $this->depthLimit ) {
225 'content' => $this->getLimitationWarning(
'unstrip-depth', $this->depthLimit )
234 $this->expandSize += strlen( $value );
235 if ( $this->expandSize > $this->sizeLimit ) {
238 'content' => $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit )
243 $this->circularRefGuard[$marker] =
true;
253 $result = array_merge( $result, $this->split( $value ) );
256 unset( $this->circularRefGuard[$marker] );
294 if ( !count( $this->data[$type] ) ) {
298 $callback =
function ( $m ) use ( $type ) {
300 if ( isset( $this->data[$type][$marker] ) ) {
301 if ( isset( $this->circularRefGuard[$marker] ) ) {
302 return $this->getWarning(
'parser-unstrip-loop-warning' );
305 if ( $this->depth > $this->highestDepth ) {
306 $this->highestDepth = $this->depth;
308 if ( $this->depth >= $this->depthLimit ) {
309 return $this->getLimitationWarning(
'unstrip-depth', $this->depthLimit );
312 $value = $this->data[$type][$marker];
313 if ( $value instanceof Closure ) {
317 $this->expandSize += strlen( $value );
318 if ( $this->expandSize > $this->sizeLimit ) {
319 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
322 $this->circularRefGuard[$marker] =
true;
324 $ret = $this->unstripType( $type, $value );
326 unset( $this->circularRefGuard[$marker] );
334 $text = preg_replace_callback( $this->regex, $callback, $text );