If passed snippet contains Twig tags, parse the string as Twig, and return the results.

@param string  $snippet
@param boolean $allowtwig

@return string
502424
public function preParse($snippet, $allowtwig)
    {
        // Quickly verify that we actually need to parse the snippet!
        if (!$allowtwig || !preg_match('/[{][{%#]/', $snippet)) {
            return $snippet;
        }

        // Don't parse Twig for live editor.
        $request = $this->app['request_stack']->getCurrentRequest();
        if ($request && $request->request->getBoolean('_live-editor-preview')) {
            return $snippet;
        }

        $snippet = html_entity_decode($snippet, ENT_QUOTES, 'UTF-8');

        $template = $this->app['twig']->createTemplate((string) $snippet);

        return twig_include($this->app['twig'], $this->getTemplateContext(), $template, [], true, false, true);
    }
1029444
public function parseSnippet($callback, $var1 = '', $var2 = '', $var3 = '')
    {
        if (method_exists($this, $callback)) {
            return call_user_func([$this, $callback], $var1, $var2, $var3);
        }

        return false;
    }
386171
function processSnippet(item, profile) {
		item.start = item.end = '';
		if (!isVeryFirstChild(item) && profile.tag_nl !== false && shouldAddLineBreak(item, profile)) {
			// check if we’re not inside inline element
			if (isRoot(item.parent) || !abbrUtils.isInline(item.parent)) {
				item.start = '\n' + item.start;
			}
		}
		
		return item;
	}
320086
public function doAddFolder($data, Form $form) {
        //Existing Check
        $existingCheck=SnippetFolder::get()->filter('Name:nocase', Convert::raw2sql($data['Name']))->filter('LanguageID', intval($data['LanguageID']));
        
        if(array_key_exists('FolderID', $data)) {
            $existingCheck=$existingCheck->filter('ParentID', intval($data['FolderID']));
        }else {
            $existingCheck->filter('ParentID', 0);
        }
        
        if($existingCheck->Count()>0) {
            $form->sessionMessage(_t('CodeBank.FOLDER_EXISTS', '_A folder already exists with that name'), 'bad');
            return $this->redirectBack();
        }
        
        
        $folder=new SnippetFolder();
        $folder->Name=$data['Name'];
        $folder->LanguageID=$data['LanguageID'];
        
        if(array_key_exists('ParentID', $data)) {
            $folder->ParentID=$data['ParentID'];
        }
        
        //Write the folder to the database
        $folder->write();
        
        
        //Find the next & previous nodes, for proper positioning (Sort isn't good enough - it's not a raw offset)
        $next=$prev=null;
        $next=SnippetFolder::get()->filter('LanguageID', $folder->LanguageID)->filter('ParentID', $folder->ParentID)->filter('Name:GreaterThan', Convert::raw2sql($folder->Title))->first();
        if(!$next) {
            $prev=SnippetFolder::get()->filter('LanguageID', $folder->LanguageID)->filter('ParentID', $folder->ParentID)->filter('Name:LessThan', Convert::raw2sql($folder->Title))->reverse()->first();
        }
        
        
        //Setup js that will add the node to the tree
        $html=CodeBank_TreeNode::create($folder, '', false)->forTemplate().'</li>';
        $parentFolder=$folder->Parent();
        $outputData=array('folder-'.$folder->ID=>array(
                                            'html'=>$html,
                                            'ParentID'=>(!empty($parentFolder) && $parentFolder!==false && $parentFolder->ID!=0 ? 'folder-'.$folder->ParentID:'language-'.$folder->LanguageID),
                                            'NextID'=>($next ? 'folder-'.$next->ID:null),
                                            'PrevID'=>($prev ? 'folder-'.$prev->ID:null)
                                        ));
        
        Requirements::customScript('window.parent.updateCodeBankTreeNodes('.json_encode($outputData).');');
        
        
        //Re-render the form
        $form->setFields(new FieldList());
        $form->setActions(new FieldList());
        $form->setMessage(_t('CodeBank.FOLDER_ADDED', '_Folder added you may now close this dialog'), 'good');
        
        return $this->customise(array(
                                    'Content'=>' ',
                                    'Form'=>$form
                                ))->renderWith('CMSDialog');
    }
1019152
protected function _tag($code)
    {
        if( $this->tag === true )
        {
            $style = Singleton::class('ZN\Hypertext\Style');

            return $style->open().$code.$style->close();
        }

        return $code;
    }
1239343
def get_snippet_by_name(cls, name):
        """"""
        name_with_dir_separators = name.replace('.', os.path.sep)
        loaded = yaml_loader.YamlLoader.load_yaml_by_relpath(cls.snippets_dirs,
                                                             name_with_dir_separators + '.yaml')
        if loaded:
            return cls._create_snippet(name, *loaded)

        raise exceptions.SnippetNotFoundException('no such snippet: {name}'.
                                                  format(name=name_with_dir_separators))
783768
public function parseArguments($namedArguments = false, $definition = false)
    {
        $args = array();
        $stream = $this->parser->getStream();

        $stream->expect(Twig_Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis');
        while (!$stream->test(Twig_Token::PUNCTUATION_TYPE, ')')) {
            if (!empty($args)) {
                $stream->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma');
            }

            if ($definition) {
                $token = $stream->expect(Twig_Token::NAME_TYPE, null, 'An argument must be a name');
                $value = new Twig_Node_Expression_Name($token->getValue(), $this->parser->getCurrentToken()->getLine());
            } else {
                $value = $this->parseExpression();
            }

            $name = null;
            if ($namedArguments && $token = $stream->nextIf(Twig_Token::OPERATOR_TYPE, '=')) {
                if (!$value instanceof Twig_Node_Expression_Name) {
                    throw new Twig_Error_Syntax(sprintf('A parameter name must be a string, "%s" given', get_class($value)), $token->getLine(), $this->parser->getFilename());
                }
                $name = $value->getAttribute('name');

                if ($definition) {
                    $value = $this->parsePrimaryExpression();

                    if (!$this->checkConstantExpression($value)) {
                        throw new Twig_Error_Syntax(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $this->parser->getFilename());
                    }
                } else {
                    $value = $this->parseExpression();
                }
            }

            if ($definition) {
                if (null === $name) {
                    $name = $value->getAttribute('name');
                    $value = new Twig_Node_Expression_Constant(null, $this->parser->getCurrentToken()->getLine());
                }
                $args[$name] = $value;
            } else {
                if (null === $name) {
                    $args[] = $value;
                } else {
                    $args[$name] = $value;
                }
            }
        }
        $stream->expect(Twig_Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis');

        return new Twig_Node($args);
    }
1322734
public function remove(string $snippet, array $params = [])
    {
        $path = $this->buildUsersPath($snippet);

        return $this->delete($path, $params);
    }
1359108
public function forTemplate() {
        $obj=$this->obj;
        if($this->obj instanceof SnippetLanguage) {
            $liAttrib='id="language-'.$obj->ID.'" data-id="language-'.$obj->ID.'"';
        }else if($this->obj instanceof SnippetFolder) {
            $liAttrib='id="folder-'.$obj->ID.'" data-id="folder-'.$obj->ID.'" data-languageID="'.$obj->LanguageID.'"';
        }else {
            $liAttrib='id="record-'.$obj->ID.'" data-id="'.$obj->ID.'" data-languageID="'.$obj->LanguageID.'"';
        }
        
        return "<li ".$liAttrib." data-pagetype=\"$obj->ClassName\" class=\"".$this->getClasses()."\">" .
                "<ins class=\"jstree-icon\">&nbsp;</ins>".
                "<a href=\"".($this->obj instanceof SnippetLanguage || $this->obj instanceof SnippetFolder ? '':$this->getLink())."\" title=\"$obj->class: ".strip_tags($obj->TreeTitle)."\">".
                "<ins class=\"jstree-icon\">&nbsp;</ins><span class=\"text\">".($obj->TreeTitle)."</span></a>";
    }
892321
def parse_snippet_css(path)
      return unless core.storage.file?(path)
      parser = ::CssParser::Parser.new
      parser.add_block! core.storage.read(path)
      apply_styles parser, "snippet"
    end
1316474
public function cmfParse(\Twig_Environment $twig, Node $node, array $options = array())
    {
        $html = "";

        if ($node instanceof ContentNode) {

            /**
             * @var ContentNode $node
             */
            $template = $this->cmfContentParser->findTemplate($node);

            $refClass = $this->cmfContentParser->getNativeClassnamimg($node);

            $generated_classes = array("ContentNode", $refClass['name']);

            /**
             * parse css classes
             */
            $display_classes = array();
            $class_string = trim($node->getClasses());

            if ($class_string)
                $display_classes = explode(" ", $class_string);

            /*
             * workaround to avoid broken grid-layouts couz of missing xs sizing
             */
            if ( strpos($class_string,'col-xs') === false && !in_array(get_class($node), $this->notGridableContentNodeClasses))
                $generated_classes[] = "col-xs-12";


            $display_classes = array_merge($display_classes, $generated_classes);
            $display_classes = array_unique($display_classes);

            $html = $twig->render($template,
                array_merge_recursive(
                    array(
                        'node' => $node,
                        'node_class' => $refClass['name'],
                        'node_namespace' => $refClass['namespace'],
                        'display_classes' => implode(" ", $display_classes),
                        'generated_classes' => implode(" ", $generated_classes)
                    )
                    , $options
                )
            );
        }

        /**
         * if user is not authenticated, strip all cmf data
         */

        if (!$this->checkUser())
            $html = $this->stripCmfData($html);

        return $html;

    }
1240409
function transformSnippet(snippet, isImportant, syntax) {
		if (typeof snippet !== 'string') {
			snippet = snippet.data;
		}
		
		if (!isSingleProperty(snippet)) {
			return snippet;
		}
		
		if (isImportant) {
			if (~snippet.indexOf(';')) {
				snippet = snippet.split(';').join(' !important;');
			} else {
				snippet += ' !important';
			}
		}
		
		return formatProperty(snippet, syntax);
	}
1232030
public static function stripTags($data, $allow_tags = null)
    {
        if (\is_array($data)) {
            foreach ($data as $k => $v) {
                $data[$k] = self::stripTags($v, $allow_tags);
            }

            return $data;
        }

        if (\is_string($data) || is_numeric($data)) {
            return strip_tags($data, $allow_tags);
        }

        return false;
    }
419524
private function decorateSnippet(array $snippet, $locale)
    {
        return array_merge(
            $snippet,
            [
                '_links' => [
                    'self' => $this->urlGenerator->generate(
                        'get_snippet',
                        ['id' => $snippet['id'], 'language' => $locale]
                    ),
                    'delete' => $this->urlGenerator->generate(
                        'delete_snippet',
                        ['id' => $snippet['id'], 'language' => $locale]
                    ),
                    'new' => $this->urlGenerator->generate('post_snippet', ['language' => $locale]),
                    'update' => $this->urlGenerator->generate(
                        'put_snippet',
                        ['id' => $snippet['id'], 'language' => $locale]
                    ),
                ],
            ]
        );
    }
172902
protected function configureSnippetHelper(SnippetHelper $snippetHelper, array $config, array $snippetsConfig)
    {
        $enableAll = isset($snippetsConfig['enable_all']) ?
            (bool)$snippetsConfig['enable_all'] :
            true;

        foreach ($snippetsConfig['snippets'] as $name => $snippetsConfig) {

            $values = [];

            // Retrive values from global config if a config key was provided
            if (isset($snippetsConfig['config_key']) && isset($config[$snippetsConfig['config_key']])) {
                $values = $config[$snippetsConfig['config_key']];
            }

            // Merge provided values, if any
            if (isset($snippetsConfig['values'])) {
                $values = array_merge_recursive($values, $snippetsConfig['values']);
            }

            $snippetHelper->appendSnippet(
                $name,
                isset($snippetsConfig['template']) ? $snippetsConfig['template'] : 'hanger-snippet/' . $name,
                $values,
                isset($snippetsConfig['placement']) ? $snippetsConfig['placement'] : null,
                isset($snippetsConfig['enabled']) ? $snippetsConfig['enabled'] : $enableAll
            );
        }

        return $snippetHelper;
    }
1245132
public function getSnippetsByUuids(array $uuids, $locale, $loadGhostContent = false)
    {
        $snippets = [];

        foreach ($uuids as $uuid) {
            try {
                $snippet = $this->documentManager->find($uuid, $locale, [
                    'load_ghost_content' => $loadGhostContent,
                ]);
                $snippets[] = $snippet;
            } catch (DocumentNotFoundException $e) {
                // ignore not found items
            }
        }

        return $snippets;
    }
805690
public static function stripTagsDeep($arr, $allowTags = '') {
		if (is_array($arr)) {
			foreach ($arr as $key => $val) {
				$arr[$key] = stripTagsDeep($val, $allowTags);
			}
		} else {
			$arr = static::stripTags($arr, $allowTags);
		}

		return $arr;
	}