This also sets the parent of the given child to this node
[element:a]
(0)[element:b]
(1)[element:c]
[element:a]->append([element:d])
[element:a]
(0)[element:b]
(1)[element:c]
(2)[element:d]
public append ( |
||
$node | the new child node to be appended |
/** * Stacks blocks into each other. * * The first block found is always the container, * all other blocks either to append, replace or prepend * to/the first block. * * @param Node $node the block node to handle * * @return $this */ protected function handleBlock(Node $node) { if (!$node->name || $node->mode === 'ignore') { //Will be handled through compileBlock when the loop encounters it return $this; } //Find all other blocks with that name foreach ($this->blocks as $block) { if ($block === $node || $block->name !== $node->name) { continue; } $mode = $block->mode; //detach from parent $block->parent->remove($block); switch ($mode) { default: /** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */ case 'replace': $node->children = []; //WANTED FALLTHROUGH! //WANTED FALLTHROUGH! case 'append': //Append to master block foreach ($block->children as $child) { $block->remove($child); $node->append($child); } break; case 'prepend': $last = null; foreach ($block->children as $child) { $block->remove($child); if (!$last) { $node->prepend($child); $last = $child; continue; } $node->insertAfter($last, $child); $last = $child; } break; } $block->mode = 'ignore'; } return $this; }
/** * Handles a <text>-token and parses it into a text-node. * * If there's a $_current element, we append it to that element, * if not, it becomes the $_current element * * @param array $token the <text>-token */ protected function handleText(array $token) { $node = $this->createNode('text', $token); $node->value = $token['value']; $node->level = $token['level']; $node->escaped = $token['escaped']; if ($this->current) { $this->current->append($node); } else { $this->current = $node; } }