50 public function execute($tokens, $config, $context) {
55 $definition = $config->getHTMLDefinition();
57 $excludes_enabled = !$config->get(
'Core.DisableExcludes');
61 $parent_name = $definition->info_parent;
69 $is_inline = $definition->info_parent_def->descendants_are_inline;
70 $context->register(
'IsInline', $is_inline);
73 $e =& $context->get(
'ErrorCollector',
true);
86 $exclude_stack = array();
91 $context->register(
'CurrentToken', $start_token);
98 for ($i = 0,
$size = count($tokens) ; $i <
$size; ) {
104 $child_tokens = array();
108 for ($j = $i, $depth = 0; ; $j++) {
113 if ($depth == 1)
continue;
118 if ($depth == 0)
break;
120 $child_tokens[] = $tokens[$j];
126 $start_token = $tokens[$i];
132 if ($count = count($stack)) {
133 $parent_index = $stack[$count-1];
134 $parent_name = $tokens[$parent_index]->name;
135 if ($parent_index == 0) {
136 $parent_def = $definition->info_parent_def;
138 $parent_def = $definition->info[$parent_name];
145 $parent_index = $parent_name = $parent_def = null;
149 if ($is_inline ===
false) {
151 if (!empty($parent_def) && $parent_def->descendants_are_inline) {
152 $is_inline = $count - 1;
156 if ($count === $is_inline) {
168 if (!empty($exclude_stack) && $excludes_enabled) {
169 foreach ($exclude_stack as $lookup) {
170 if (isset($lookup[$tokens[$i]->name])) {
189 $def = $definition->info_parent_def;
191 $def = $definition->info[$tokens[$i]->name];
195 if (!empty($def->child)) {
197 $result = $def->child->validateChildren(
198 $child_tokens, $config, $context);
205 $excludes = $def->excludes;
220 if (!empty($excludes)) $exclude_stack[] = $excludes;
230 $e->send(E_ERROR,
'Strategy_FixNesting: Node excluded');
232 $e->send(E_ERROR,
'Strategy_FixNesting: Node removed');
237 $length = $j - $i + 1;
240 array_splice($tokens, $i, $length);
255 if (!$parent_def->child->allow_empty) {
268 $length = $j - $i - 1;
271 if (empty(
$result) && $length) {
272 $e->send(E_ERROR,
'Strategy_FixNesting: Node contents removed');
274 $e->send(E_WARNING,
'Strategy_FixNesting: Node reorganized');
279 array_splice($tokens, $i + 1, $length,
$result);
289 if (!empty($excludes)) $exclude_stack[] = $excludes;
304 $size = count($tokens);
311 if ($i == 0 || $i == $size - 1) {
313 $s_excludes = $definition->info_parent_def->excludes;
315 $s_excludes = $definition->info[$tokens[$i]->name]->excludes;
318 array_pop($exclude_stack);
330 array_shift($tokens);
334 $context->destroy(
'IsInline');
335 $context->destroy(
'CurrentToken');