/** * Parse next filter token. * * @return FilterNode */ protected function parseFilter() { $block = null; $token = $this->expectTokenType('filter'); $attributes = $this->acceptTokenType('attributes'); if ($this->lexer->predictToken(2)->type === 'text') { $block = $this->parseTextBlock(); } else { $block = $this->parseBlock(); } $node = new FilterNode($token->value, null !== $attributes ? $attributes->attributes : array(), $this->lexer->getCurrentLine()); $node->setBlock($block); return $node; }
/** * Dump filter node. * * @param FilterNode $node filter node * @param integer $level indentation level * * @return string */ protected function dumpFilter(FilterNode $node, $level = 0) { $text = ''; if ($node->getBlock()) { $text = $this->dumpNode($node->getBlock(), $level + 1); } switch ($node->getName()) { case 'css': $opening_tag = '<style type="text/css">'; $closing_tag = '</style>'; break; case 'php': $opening_tag = '<?php'; $closing_tag = '?>'; break; case 'cdata': $opening_tag = '<![CDATA['; $closing_tag = ']]>'; break; case 'javascript': $opening_tag = '<script type="text/javascript">'; $closing_tag = '</script>'; break; } $indent = str_repeat(' ', $level); $html = $indent . $opening_tag . "\n"; $html .= $text . "\n"; $html .= $indent . $closing_tag; return $html; }