Partially renders the escaped variable tokens

@param *array $node
@param *array $open

@return string
329268
protected function generateEscape($node, &$open)
    {
        $node['value'] = trim($node['value']);

        //lookout for tokenizer
        $tokenized = $this->tokenize($node);
        if ($tokenized) {
            return $tokenized;
        }

        list($name, $args, $hash) = $this->parseArguments($node['value']);

        //if it's a helper
        $helper = $this->resolveStatic(HandlebarsRuntime::class, 'getHelper', $name);

        if ($helper) {
            //form hash
            foreach ($hash as $key => $value) {
                $hash[$key] = sprintf(self::BLOCK_OPTIONS_HASH_KEY_VALUE, $key, $value);
            }

            $args[] = $this->prettyPrint(self::BLOCK_OPTIONS_OPEN, 0, 2)
                . $this->prettyPrint(sprintf(self::BLOCK_OPTIONS_NAME, $name))
                . $this->prettyPrint(sprintf(self::BLOCK_OPTIONS_ARGS, str_replace("'", '\\\'', $node['value'])))
                . $this->prettyPrint(sprintf(self::BLOCK_OPTIONS_HASH, implode(', \r\t', $hash)))
                . $this->prettyPrint(self::BLOCK_OPTIONS_FN_EMPTY)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_EMPTY)
                . $this->prettyPrint(self::BLOCK_OPTIONS_CLOSE, -1);

            return $this->prettyPrint(sprintf(self::BLOCK_ESCAPE_HELPER_OPEN, $name), -1)
                . $this->prettyPrint('\r\t' . implode(', \r\t', $args), 1, -1)
                . $this->prettyPrint(self::BLOCK_ESCAPE_HELPER_CLOSE);
        }

        //it's a value ?
        $value = str_replace(['[', ']', '(', ')'], '', $node['value']);
        $value = str_replace("'", '\\\'', $value);
        return $this->prettyPrint(sprintf(self::BLOCK_ESCAPE_VALUE, $value));
    }
540508
protected function pStmts(array $nodes, $indent = true)
    {
        $result = '';

        foreach ($nodes as $node) {
            $row = "";

            $cur_ln = $this->cur_ln;

            $comments = $node->getAttribute('comments', array());
            $comments = !empty($comments) ? ($this->pComments($node->getAttribute('comments', array())) . "\n") : "";
            $this->cur_ln += substr_count($comments, "\n");

            if ($node->getLine() > $this->cur_ln) {
                $row .= str_repeat("\n", $node->getLine() - $this->cur_ln);
                $this->cur_ln += substr_count($row, "\n");
            }

            $row .= $comments
                . $this->p($node)
                . ($node instanceof \PhpParser\Node\Expr ? ';' : '');

            $this->cur_ln = $cur_ln + substr_count($row, "\n"); // get rid of cur_ln modifications in deeper context

            $result .= $row;
        }

        if ($indent) {
            return preg_replace('~\n(?!$|' . $this->noIndentToken . ')~', "\n    ", $result);
        } else {
            return $result;
        }
    }
1134577
protected function generateVariable($node, &$open)
    {
        $node['value'] = trim($node['value']);

        //look out for else
        if ($node['value'] === 'else') {
            $open[$this->findSection($open)]['else'] = true;

            return $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_5, -1)
                . $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_6)
                . $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_7)
                . $this->prettyPrint(self::BLOCK_OPTIONS_FN_CLOSE)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_OPEN)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_BODY_1)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_BODY_2)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_BODY_3)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_BODY_4, 0, 1);
        }

        //lookout for tokenizer
        $tokenized = $this->tokenize($node);
        if ($tokenized) {
            return $tokenized;
        }

        list($name, $args, $hash) = $this->parseArguments($node['value']);

        //if it's a helper
        $helper = $this->resolveStatic(HandlebarsRuntime::class, 'getHelper', $name);

        if ($helper) {
            //form hash
            foreach ($hash as $key => $value) {
                $hash[$key] = sprintf(self::BLOCK_OPTIONS_HASH_KEY_VALUE, $key, $value);
            }

            $args[] = $this->prettyPrint(self::BLOCK_OPTIONS_OPEN, 0, 2)
                . $this->prettyPrint(sprintf(self::BLOCK_OPTIONS_NAME, $name))
                . $this->prettyPrint(sprintf(self::BLOCK_OPTIONS_ARGS, str_replace("'", '\\\'', $node['value'])))
                . $this->prettyPrint(sprintf(self::BLOCK_OPTIONS_HASH, implode(', \r\t', $hash)))
                . $this->prettyPrint(self::BLOCK_OPTIONS_FN_EMPTY)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_EMPTY)
                . $this->prettyPrint(self::BLOCK_OPTIONS_CLOSE, -1);

            return $this->prettyPrint(sprintf(self::BLOCK_VARIABLE_HELPER_OPEN, $name), -1)
                . $this->prettyPrint('\r\t' . implode(', \r\t', $args), 1, -1)
                . $this->prettyPrint(self::BLOCK_VARIABLE_HELPER_CLOSE);
        }

        //it's a value ?
        $value = str_replace(['[', ']', '(', ')'], '', $node['value']);
        $value = str_replace("'", '\\\'', $value);
        return $this->prettyPrint(sprintf(self::BLOCK_VARIABLE_VALUE, $value));
    }
78902
function resolve($node,array $hive=NULL,$ttl=0,$persist=FALSE,$escape=NULL) {
		$fw=$this->fw;
		$cache=Cache::instance();
		if ($escape!==NULL) {
			$esc=$fw->ESCAPE;
			$fw->ESCAPE=$escape;
		}
		if ($ttl || $persist)
			$hash=$fw->hash($fw->serialize($node));
		if ($ttl && $cache->exists($hash,$data))
			return $data;
		if ($persist) {
			if (!is_dir($tmp=$fw->TEMP))
				mkdir($tmp,Base::MODE,TRUE);
			if (!is_file($this->file=($tmp.
				$fw->SEED.'.'.$hash.'.php')))
				$fw->write($this->file,$this->build($node));
			if (isset($_COOKIE[session_name()]) &&
				!headers_sent() && session_status()!=PHP_SESSION_ACTIVE)
				session_start();
			$fw->sync('SESSION');
			$data=$this->sandbox($hive);
		}
		else {
			if (!$hive)
				$hive=$fw->hive();
			if ($fw->ESCAPE)
				$hive=$this->esc($hive);
			extract($hive);
			unset($hive);
			ob_start();
			eval(' ?>'.$this->build($node).'<?php ');
			$data=ob_get_clean();
		}
		if ($ttl)
			$cache->set($hash,$data,$ttl);
		if ($escape!==NULL)
			$fw->ESCAPE=$esc;
		return $data;
	}
1016841
private function generateTmlTags($node) {
        $buffer = "";
        foreach($node->childNodes as $child) {
            if ($child->nodeType == 3) {                    // text node
                $buffer = $buffer . $child->wholeText;
            } else {
                $buffer = $buffer . $this->generateTmlTags($child);
            }
        }

        $token_context = $this->generateHtmlToken($node);
        $token = $this->adjustName($node);
        $token = $this->contextualize($token, $token_context);

        $value = $this->sanitizeValue($buffer);

        if ($this->isSelfClosingNode($node))
            return '{'.$token.'}';

        if ($this->isShortToken($token, $value))
            return '['.$token.': '.$value.']';

        return '['.$token.']'.$value.'[/'.$token.']';
    }
398501
public function getDeclarationLineFromNode($node): string
    {
        // If node is part of a declaration list, build a declaration line that discludes other elements in the list
        //  - [PropertyDeclaration] // public $a, [$b = 3], $c; => public $b = 3;
        //  - [ConstDeclaration|ClassConstDeclaration] // "const A = 3, [B = 4];" => "const B = 4;"
        if (
            ($declaration = ParserHelpers\tryGetPropertyDeclaration($node)) && ($elements = $declaration->propertyElements) ||
            ($declaration = ParserHelpers\tryGetConstOrClassConstDeclaration($node)) && ($elements = $declaration->constElements)
        ) {
            $defLine = $declaration->getText();
            $defLineStart = $declaration->getStart();

            $defLine = \substr_replace(
                $defLine,
                $node->getFullText(),
                $elements->getFullStart() - $defLineStart,
                $elements->getFullWidth()
            );
        } else {
            $defLine = $node->getText();
        }

        // Trim string to only include first line
        $defLine = \rtrim(\strtok($defLine, "\n"), "\r");

        // TODO - pretty print rather than getting text

        return $defLine;
    }
233918
static function render($node, &$document = null)
    {
        $document = $document ?: new \DOMDocument;
        $document->appendChild(static::renderNode($node, $document));

        return $document->saveHTML();
    }
885902
protected function renderNodes($nodes)
    {
        $lines = [];

        if (!empty($nodes)) {

            $nodesOptions = $this->nodesOptions;
            $tag = ArrayHelper::remove($nodesOptions, 'tag', 'ol');
            $lines[] =  Html::beginTag($tag, $nodesOptions);

            foreach ($nodes as $node) {
                if (isset($node['visible']) && !$node['visible']) {
                    continue;
                }
                $lines[] = $this->renderNode($node);
            }

            $lines[] =  Html::endTag($tag); 
        }

        return implode("\n", $lines);
    }
621224
public function link($node, $query = '')
    {
        if (is_array($node)) {
            $links = array();
            $nodes = $node;
            foreach ($nodes as $node) {
                $links[] = $this->link($node, $query);
            }

            return implode(', ', $links);
        }

        return '<a href="'.route($node->getURL()).$query.'">'.$node->getName().'</a>';
    }
945853
protected function _repeat(array $node) {
		$attrib=$node['@attrib'];
		unset($node['@attrib']);
		return
			'<?php '.
				(isset($attrib['counter'])?
					(($ctr=$this->token($attrib['counter'])).'=0; '):'').
				'foreach (('.
				$this->token($attrib['group']).'?:[]) as '.
				(isset($attrib['key'])?
					($this->token($attrib['key']).'=>'):'').
				$this->token($attrib['value']).'):'.
				(isset($ctr)?(' '.$ctr.'++;'):'').' ?>'.
				$this->build($node).
			'<?php endforeach; ?>';
	}
141337
protected function renderNodeActions($node)
    {
        $lines = [];

        $nodeActionsOptions = $this->nodeActionsOptions;
        $tag = ArrayHelper::remove($nodeActionsOptions, 'tag', 'span');
        $lines[] = Html::beginTag($tag, $nodeActionsOptions);

        foreach ($this->nodeActions as $actionName => $actionValue) {
            $lines[] = $this->renderNodeAction($node, $actionName, $actionValue);
        }

        $lines[] =  Html::endTag($tag);

        return implode("\n", $lines);
    }
796912
private function renderNodeNotTranslatedPage(Node $node)
    {
        //try to find a parent node with the correct translation, if there is none allow copy.
        //if there is a parent but it doesn't have the language to copy to don't allow it
        $parentNode = $node->getParent();
        if ($parentNode) {
            $parentNodeTranslation = $parentNode->getNodeTranslation(
                $this->locale,
                true
            );
            $parentsAreOk = false;

            if ($parentNodeTranslation) {
                $parentsAreOk = $this->em->getRepository(
                    'KunstmaanNodeBundle:NodeTranslation'
                )->hasParentNodeTranslationsForLanguage(
                    $node->getParent()->getNodeTranslation(
                        $this->locale,
                        true
                    ),
                    $this->locale
                );
            }
        } else {
            $parentsAreOk = true;
        }

        return $this->render(
            'KunstmaanNodeBundle:NodeAdmin:pagenottranslated.html.twig',
            array(
                'node' => $node,
                'nodeTranslations' => $node->getNodeTranslations(
                    true
                ),
                'copyfromotherlanguages' => $parentsAreOk,
            )
        );
    }
849716
public function enterNode(PhpParser\Node $node)
    {
        if ($node instanceof PhpParser\Node\Expr\Assign) {
            $left_var_id = ExpressionAnalyzer::getRootVarId($node->var, $this->this_class_name);
            $right_var_id = ExpressionAnalyzer::getRootVarId($node->expr, $this->this_class_name);

            if ($left_var_id) {
                $this->assignment_map[$left_var_id][$right_var_id ?: 'isset'] = true;
            }

            return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN;
        } elseif ($node instanceof PhpParser\Node\Expr\PostInc
            || $node instanceof PhpParser\Node\Expr\PostDec
            || $node instanceof PhpParser\Node\Expr\PreInc
            || $node instanceof PhpParser\Node\Expr\PreDec
            || $node instanceof PhpParser\Node\Expr\AssignOp
        ) {
            $var_id = ExpressionAnalyzer::getRootVarId($node->var, $this->this_class_name);

            if ($var_id) {
                $this->assignment_map[$var_id][$var_id] = true;
            }

            return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN;
        } elseif ($node instanceof PhpParser\Node\Expr\FuncCall) {
            foreach ($node->args as $arg) {
                $arg_var_id = ExpressionAnalyzer::getRootVarId($arg->value, $this->this_class_name);

                if ($arg_var_id) {
                    $this->assignment_map[$arg_var_id][$arg_var_id] = true;
                }
            }
        } elseif ($node instanceof PhpParser\Node\Stmt\Unset_) {
            foreach ($node->vars as $arg) {
                $arg_var_id = ExpressionAnalyzer::getRootVarId($arg, $this->this_class_name);

                if ($arg_var_id) {
                    $this->assignment_map[$arg_var_id][$arg_var_id] = true;
                }
            }
        }

        return null;
    }
205847
public function renderButton(&$node)
	{
		// Get the button type.
		$type = $node[0];

		$button = $this->loadButtonType($type);

		// Check for error.
		if ($button === false)
		{
			return \Lang::txt('JLIB_HTML_BUTTON_NOT_DEFINED', $type);
		}
		return $button->render($node);
	}
19433
protected function generateClose(array $node, array &$open)
    {
        $node['value'] = trim($node['value']);

        if ($this->findSection($open, $node['value']) === false) {
            throw HandlebarsException::forUnknownEnd($node['value'], $node['line']);
        }

        $buffer = '';

        $i = $this->findSection($open);

        if (!isset($open[$i]['else'])) {
            $buffer .= $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_5, -1);
            $buffer .= $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_6);
            $buffer .= $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_7);
            $buffer .= $this->prettyPrint(self::BLOCK_OPTIONS_FN_CLOSE);
            $buffer .= $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_EMPTY);
        } else {
            $buffer .= $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_BODY_5);
            $buffer .= $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_BODY_6);
            $buffer .= $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_BODY_7);
            $buffer .= $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_CLOSE, -1);
        }

        unset($open[$i]);

        $buffer .= $this->prettyPrint(self::BLOCK_OPTIONS_CLOSE, -1);
        $buffer .= $this->prettyPrint(self::BLOCK_ESCAPE_HELPER_CLOSE, -1);

        return $buffer;
    }
777736
protected static function renderNode($node, $document)
    {
        if (static::isTag($node)) {
            # Strip the leading "#"
            $tagName    = substr(array_shift($node), 1);
            $attributes = array();

            if (sizeof($node) > 2) {
                throw new \UnexpectedValueException(
                    "Tags must not consist of more than three elements"
                );
            }

            foreach ($node as $argv) {
                # Is the argument an associative array of attributes?
                if (is_array($argv) and count(array_filter(array_keys($argv), "is_string")) > 0) {
                    $attributes = $argv;
                } else {
                    $content = $argv;
                }
            }

            $el = $document->createElement($tagName);

            foreach ($attributes as $attr => $value) {
                if (is_array($value)) $value = join(" ", $value);

                $el->setAttribute($attr, (string) $value);
            }

            if (isset($content)) {
                $el->appendChild(static::renderNode($content, $document));
            }
        } else if (is_array($node)) {
            $el = $document->createDocumentFragment();

            foreach ($node as $child) {
                $el->appendChild(static::renderNode($child, $document));
            }
        } else {
            $node = (string) $node;
            if (!empty($node)) $node .= "\n";
            $el = $document->createTextNode($node);
        }

        return $el;
    }
378261
protected function generateVariable(array $node, array &$open): string
    {
        $node['value'] = trim($node['value']);

        //look out for else
        if ($node['value'] === 'else') {
            $open[$this->findSection($open)]['else'] = true;

            return $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_5, -1)
                . $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_6)
                . $this->prettyPrint(self::BLOCK_OPTIONS_FN_BODY_7)
                . $this->prettyPrint(self::BLOCK_OPTIONS_FN_CLOSE)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_OPEN)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_BODY_1)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_BODY_2)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_BODY_3)
                . $this->prettyPrint(self::BLOCK_OPTIONS_INVERSE_BODY_4, 0, 1);
        }

        //lookout for partials
        if (mb_substr($node["value"], 0, 2) === "> ") {
            return $this->generatePartial($node);
        }

        $argumentList = $this->parseArguments($node['value']);

        //if it's a helper
        if ($this->runtime->getHelper($argumentList->getName())) {
            return $this->generateHelper($argumentList, $node['value'], self::BLOCK_HELPER_VARIABLE_RESULTCHECK);
        }

        //it's a value ?
        $value = str_replace(array('[', ']', '(', ')'), '', $node['value']);
        $value = str_replace("'", '\\\'', $value);
        return $this->prettyPrint(sprintf(self::BLOCK_VARIABLE_VALUE, $value));
    }