Process the given html fragment using the given function
@param $content Html string
@param $processor Function that accepts a DOMDocument as only parameter
@return String
432646
public static function processHtml($content, callable $processor) {
    $doc = new \DOMDocument();
    $doc->loadHTML('<html>'.trim(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8')).'</html>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
    $processor($doc);
    return trim(str_replace(['<html>', '</html>'], '', $doc->saveHTML()));
  }
99194
public static function coreHTMLElement($element, $content, array $attrs = []) {

        $template = "<%element%%attributes%>%innerHTML%</%element%>";

        $attributes = trim(StringHelper::parseArray($attrs));
        if (0 < strlen($attributes)) {
            $attributes = " " . $attributes;
        }

        $innerHTML = null !== $content ? trim($content, " ") : "";

        return StringHelper::replace($template, ["%element%", "%attributes%", "%innerHTML%"], [trim($element), $attributes, $innerHTML]);
    }
566601
protected function _render($content)
    {
        $this->_textMessage = $this->_htmlMessage = '';

        $content = implode("\n", $content);
        $rendered = $this->_renderTemplates($content);

        $this->_createBoundary();
        $msg = [];

        $contentIds = array_filter((array)Hash::extract($this->_attachments, '{s}.contentId'));
        $hasInlineAttachments = count($contentIds) > 0;
        $hasAttachments = !empty($this->_attachments);
        $hasMultipleTypes = count($rendered) > 1;
        $multiPart = ($hasAttachments || $hasMultipleTypes);

        $boundary = $relBoundary = $textBoundary = $this->_boundary;

        if ($hasInlineAttachments) {
            $msg[] = '--' . $boundary;
            $msg[] = 'Content-Type: multipart/related; boundary="rel-' . $boundary . '"';
            $msg[] = '';
            $relBoundary = $textBoundary = 'rel-' . $boundary;
        }

        if ($hasMultipleTypes && $hasAttachments) {
            $msg[] = '--' . $relBoundary;
            $msg[] = 'Content-Type: multipart/alternative; boundary="alt-' . $boundary . '"';
            $msg[] = '';
            $textBoundary = 'alt-' . $boundary;
        }

        if (isset($rendered['text'])) {
            if ($multiPart) {
                $msg[] = '--' . $textBoundary;
                $msg[] = 'Content-Type: text/plain; charset=' . $this->_getContentTypeCharset();
                $msg[] = 'Content-Transfer-Encoding: ' . $this->_getContentTransferEncoding();
                $msg[] = '';
            }
            $this->_textMessage = $rendered['text'];
            $content = explode("\n", $this->_textMessage);
            $msg = array_merge($msg, $content);
            $msg[] = '';
        }

        if (isset($rendered['html'])) {
            if ($multiPart) {
                $msg[] = '--' . $textBoundary;
                $msg[] = 'Content-Type: text/html; charset=' . $this->_getContentTypeCharset();
                $msg[] = 'Content-Transfer-Encoding: ' . $this->_getContentTransferEncoding();
                $msg[] = '';
            }
            $this->_htmlMessage = $rendered['html'];
            $content = explode("\n", $this->_htmlMessage);
            $msg = array_merge($msg, $content);
            $msg[] = '';
        }

        if ($textBoundary !== $relBoundary) {
            $msg[] = '--' . $textBoundary . '--';
            $msg[] = '';
        }

        if ($hasInlineAttachments) {
            $attachments = $this->_attachInlineFiles($relBoundary);
            $msg = array_merge($msg, $attachments);
            $msg[] = '';
            $msg[] = '--' . $relBoundary . '--';
            $msg[] = '';
        }

        if ($hasAttachments) {
            $attachments = $this->_attachFiles($boundary);
            $msg = array_merge($msg, $attachments);
        }
        if ($hasAttachments || $hasMultipleTypes) {
            $msg[] = '';
            $msg[] = '--' . $boundary . '--';
            $msg[] = '';
        }

        return $msg;
    }
885620
function process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace )
    {
        switch ( $functionName )
        {
            case $this->BlockName:
            {
                // Check for disabled cache.
                $ini = eZINI::instance();
                if ( $ini->variable( 'TemplateSettings', 'TemplateCache' ) != 'enabled' )
                {
                    $text = eZTemplateCacheFunction::processUncached( $tpl, $functionChildren,
                                                                      $rootNamespace, $currentNamespace );
                    $textElements[] = $text;
                    return;
                }
                else
                {
                    $text = eZTemplateCacheFunction::processCachedPreprocess( $tpl,  $functionChildren,
                                                                              $functionParameters, $functionPlacement,
                                                                              $rootNamespace, $currentNamespace );
                    $textElements[] = $text;
                }
            } break;
        }
    }
41603
protected function getHtml( $content )
	{
		$site = Route::input( 'site', Input::get( 'site', 'default' ) );
		return View::make( 'shop::jqadm.index', array( 'content' => $content, 'site' => $site ) );
	}
810431
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {
        $operation = $this->getOperation($request);

        $arguments = [];
        foreach ($operation->getParameters() as $parameter) {
            $arguments[] = $request->getAttribute($parameter->getName());
        }

        $result = call_user_func_array($this->commands[$operation->getId()], $arguments);

        return $delegate->process($request->withAttribute(self::ATTRIBUTE, $result));
    }
892335
protected function getInnerInstruction($content, $instruction)
    {
        $sources      = $this->getStringsBetween($content, "[[{$instruction}]]", "[[/{$instruction}]]");
        $replacements = [];

        foreach ($sources as $index => $source) {
            $toReplace            = $source;
            $source               = $this->clearCondition($source);
            $replacements[$index] = [
                'to_replace' => $toReplace,
                'cleared'    => $source
            ];
        }

        return $replacements;
    }
1230357
public static function processImageHtml($html, PageInterface $page)
    {
        $excerpt = static::getExcerptFromHtml($html, 'img');

        $original_src = $excerpt['element']['attributes']['src'];
        $excerpt['element']['attributes']['href'] = $original_src;

        $excerpt = static::processLinkExcerpt($excerpt, $page, 'image');

        $excerpt['element']['attributes']['src'] = $excerpt['element']['attributes']['href'];
        unset ($excerpt['element']['attributes']['href']);

        $excerpt = static::processImageExcerpt($excerpt, $page);

        $excerpt['element']['attributes']['data-src'] = $original_src;

        $html = static::getHtmlFromExcerpt($excerpt);

        return $html;
    }
1180355
public function edit($content)
    {
        if (!array_key_exists('selectOptions', $this->_editViewData)) {
            $this->_editViewData['selectOptions'] = [];
            $selectOptions = BlockSelectOption::where('block_id', '=', $this->_block->id)->get();
            foreach ($selectOptions as $selectOption) {
                $this->_editViewData['selectOptions'][$selectOption->value] = $selectOption->option;
            }
            if (preg_match('/^#[a-f0-9]{6}$/i', key($selectOptions))) {
                $this->_editViewData['class'] = 'select_colour';
            }
        }
        return parent::edit($content);
    }
1047280
public function process($content, array $options = [])
    {
        $found = false;
        if (is_string($content)) {
            $tagNames = array_keys($this->tagNames);
            $tagNames[] = 'component';
            foreach ($tagNames as $tagName) {
                if (strpos($content, '<' . $tagName) !== false) {
                    $found = true;
                    break;
                }
            }
        }
        if ($content instanceof \IvoPetkov\HTMLServerComponent) {
            $found = true;
        }
        if ($found) {
            if (self::$newCompilerCache === null) {
                self::$newCompilerCache = new \IvoPetkov\BearFramework\Addons\HTMLServerComponents\Internal\Compiler();
            }
            $compiler = clone(self::$newCompilerCache);
            foreach ($this->aliases as $alias => $original) {
                $compiler->addAlias($alias, $original);
            }
            foreach ($this->tagNames as $tagName => $src) {
                $compiler->addTag($tagName, $src);
            }
            return $compiler->process($content, $options);
        }
        return $content;
    }
582648
public static function createFromContent($content)
    {
        $domDocument = new \DOMDocument();

        @$domDocument->loadHTML($content);

        $xpathQueryBuilder = new XpathQueryBuilder();

        $xpathQueryBuilder->setDomXpath(new \DOMXPath($domDocument));

        return $xpathQueryBuilder;
    }
622549
protected function processTemplate(DOMDocument $document, DOMElement $template)
    {
        $content = null;
        $templateName = $template->getAttribute('name');
        $templateType = $template->hasAttribute('type') ? $template->getAttribute('type') : 'tag';
        $parameters = array(
            'name' => $templateName,
            'params' => $this->extractConfiguration($template),
        );

        if ($template->getElementsByTagName('ezcontent')->length > 0) {
            $contentNode = $template->getElementsByTagName('ezcontent')->item(0);
            switch ($templateType) {
                case 'style':
                    $parameters['content'] = $this->getCustomStyleContent($contentNode);
                    break;
                case 'tag':
                default:
                    $parameters['content'] = $this->getCustomTagContent($contentNode);
                    break;
            }
        }

        if ($template->hasAttribute('ezxhtml:align')) {
            $parameters['align'] = $template->getAttribute('ezxhtml:align');
        }

        $content = $this->renderer->renderTemplate(
            $templateName,
            $templateType,
            $parameters,
            $template->localName === 'eztemplateinline'
        );

        if (isset($content)) {
            // If current tag is wrapped inside another template tag we can't use CDATA section
            // for its content as these can't be nested.
            // CDATA section will be used only for content of root wrapping tag, content of tags
            // inside it will be added as XML fragments.
            if ($this->isWrapped($template)) {
                $fragment = $document->createDocumentFragment();
                $fragment->appendXML($content);
                $template->parentNode->replaceChild($fragment, $template);
            } else {
                $payload = $document->createElement('ezpayload');
                $payload->appendChild($document->createCDATASection($content));
                $template->appendChild($payload);
            }
        }
    }
88052
public function parseBlock(Text $content, Container $target)
    {
        $content->handle(
            '{
                ^
                [ ]{0,3}
                ([^>\-*=\ \n].*)
                [ ]*
                \n
                [ ]{0,3}
                (=+|-+)
                [ ]*
                \n*
                $
            }mx',
            function (Text $whole, Text $content, Text $mark) use ($target) {
                $level = (substr($mark, 0, 1) == '=') ? 1 : 2;

                $heading = new Heading($content->trim(), $level);
                $target->addChild($heading);

                $this->inlineParser->queue($heading->getText(), $heading);
            },
            function (Text $part) use ($target) {
                $this->next->parseBlock($part, $target);
            }
        );
    }
344029
private function renderTextAndHtml(&$content, $text, $html, $encoding, $boundary)
    {
        $uid = uniqid();
        $boundary2 = "x----_=_NextPart_003_$uid";
        $content .= "\r\n--$boundary\r\n";
        $content .= "Content-Type: multipart/alternative;\r\n\tboundary=\"$boundary2\"\r\n";
        $this->renderPlainText($content, $text, $encoding, $boundary2);
        $this->renderHtml($content, $html, $encoding, $boundary2);
        $content .= "\r\n--$boundary2--\r\n";
    }
997382
protected function doCompile($_content)
    {
        /* here is where the compiling takes place. Smarty
          tags in the templates are replaces with PHP code,
          then written to compiled files. */
        // init the lexer/parser to compile the template
        $this->lex = new $this->lexer_class($_content, $this);
        $this->parser = new $this->parser_class($this->lex, $this);
        if ($this->inheritance_child) {
            // start state on child templates
            $this->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
        }
        if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
            $mbEncoding = mb_internal_encoding();
            mb_internal_encoding('ASCII');
        } else {
            $mbEncoding = null;
        }

        if ($this->smarty->_parserdebug) {
            $this->parser->PrintTrace();
            $this->lex->PrintTrace();
        }
        // get tokens from lexer and parse them
        while ($this->lex->yylex() && !$this->abort_and_recompile) {
            if ($this->smarty->_parserdebug) {
                echo "<pre>Line {$this->lex->line} Parsing  {$this->parser->yyTokenName[$this->lex->token]} Token " .
                    htmlentities($this->lex->value) . "</pre>";
            }
            $this->parser->doParse($this->lex->token, $this->lex->value);
        }

        if ($this->abort_and_recompile) {
            // exit here on abort
            return false;
        }
        // finish parsing process
        $this->parser->doParse(0, 0);
        if ($mbEncoding) {
            mb_internal_encoding($mbEncoding);
        }
        // check for unclosed tags
        if (count($this->_tag_stack) > 0) {
            // get stacked info
            list($openTag, $_data) = array_pop($this->_tag_stack);
            $this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag . "{$this->smarty->right_delimiter} tag");
        }
        // return compiled code
        // return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue);
        return $this->parser->retvalue;
    }
373310
public function renderContent($content = null)
    {
        $repository = $this->editor->getRepository();

        if (null === $content) {
            if (null !== $page = $this->pageHelper->getCurrent()) {
                if (null === $content = $repository->loadSubjectContent($page)) {
                    if ($page->isAdvanced()) {
                        $content = $this->editor->createDefaultContent($page);
                        $this->persist($page);
                    } elseif (0 < strlen($html = $page->getHtml())) {
                        return $html;
                    } else {
                        return $this->config['default_content'];
                    }
                }
            } else {
                throw new Exception\RenderingException('Undefined content.');
            }
        } elseif ($content instanceof CM\ContentSubjectInterface) {
            if (null === $element = $repository->loadSubjectContent($content)) {
                $element = $this->editor->createDefaultContent($content);
                $this->persist($content);
            }
            $content = $element;
        } elseif (is_string($content)) {
            if (null === $element = $this->editor->getRepository()->findContentByName($content)) {
                $this->persist($element = $this->editor->createDefaultContent($content));
            }
            $content = $element;
        }

        if ($content instanceof EM\ContentInterface) {
            $this->tagManager->addTags($content->getEntityTag());

            $content = $this->editor->getViewBuilder()->buildContent($content);
        }

        if (!$content instanceof View\ContentView) {
            throw new Exception\InvalidArgumentException(
                'Expected string or instance of ' . CM\ContentSubjectInterface::class . ', ' .
                EM\ContentInterface::class . ' or ' . View\ContentView::class
            );
        }

        /** @noinspection PhpInternalEntityUsedInspection */
        return $this->getTemplate()->renderBlock('cms_content', [
            'content' => $content,
        ]);
    }
884688
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {
        $operation = $this->getOperation($request);

        foreach ($operation->getParameters() as $parameter) {
            $name    = $parameter->getName();
            $request = $request->withAttribute(
                $name,
                $this->processorBuilder
                    ->build($this->getOperation($request)->getParameter($name)->getSchema())
                    ->hydrate($request->getAttribute($name))
            );
        }

        return $delegate->process($request);
    }