Answering this question myself with an alternative because there were no other answers
The way I managed to get the result I wanted is to just give up on the original first part of the question: "What I'd like to know is if it is possible at all to match and/or replace the results of parsing the nested tag (so what the nested tag outputs)" and just move along to the second part, "if that is not possible, is it possible to make the tag behave differently when nested inside a tag".
The way I did this is by defining a variable within the class, and then changing that whether I was doing a recursiveTagParse
on the content of a or not. The code in Test.php would then be:
public static function init( &$parser ) {
$parser->setHook( 'testfoo', array( new self(), 'firstTag' ) );
$parser->setHook( 'testbar', array( new self(), 'secondTag' ) );
return true;
}
function firstTag($input, $attr = array(), $parser, $frame) {
$this::$nested = true;
$newinput = $parser->recursiveTagParse($input);
$this::$nested = false;
return preg_match_all("/ /", $newinput);
}
function secondTag($input, $attr = array(), $parser, $frame) {
if ($this::$nested) {
$output = 'Display for when nested'.$input;
} else {
$output = 'Display for when not nested'.$input;
}
return htmlspecialchars($output);
}
}
That way I was still able to make the <testbar>
tag behave differently when inside the <testfoo>
tag. I'm not sure if this is the way it's supposed to be done, but it works.
PS: I've also ignored the $frame->newChild()
code, since that didn't seem to work, and no clear documentation or examples were available.