22 public function __construct( $options, callable $shouldModifyCallback, callable $modifyCallback ) {
23 parent::__construct( $options );
24 $this->shouldModifyCallback = $shouldModifyCallback;
25 $this->modifyCallback = $modifyCallback;
28 public function element( SerializerNode $parent, SerializerNode $node, $contents ) {
29 if ( ( $this->shouldModifyCallback )( $node ) ) {
31 $node->attrs = clone $node->attrs;
32 $newNode = ( $this->modifyCallback )( $node );
33 Assert::parameterType( SerializerNode::class, $newNode,
'return value' );
34 return parent::element( $parent, $newNode, $contents );
36 return parent::element( $parent, $node, $contents );