@param string $text Text to render

@throws \RuntimeException
968828
public function render(string $text)
    {
        $text = explode("\n", trim($text));
        $min  = PHP_INT_MAX;
        $max  = 0;
        foreach ($text as $line) {
            $len = strlen(strip_tags($line, $this->options[self::ALLOWED_TAGS]));
            if ($len > $max) {
                $max = $len;
            }
            if ($len < $min) {
                $min = $len;
            }
        }

        // excluding border
        $cols = $max + $this->options[self::PADDING_LEFT_RIGHT] * 2;

        $lines = [];

        // top margin
        for ($i = 0; $i < $this->options[self::MARGIN_TOP]; $i++) {
            $lines[] = '';
        }

        // top
        $lines[] = $this->options[self::TOP_LEFT]
            . implode('', array_fill(0, $cols, $this->options[self::HORIZONTAL_LINE]))
            . $this->options[self::TOP_RIGHT];

        // padding top
        for ($i = 0; $i < $this->options[self::PADDING_TOP_BOTTOM]; $i++) {
            $lines[] = $this->options[self::VERTICAL_LINE]
                . implode('', array_fill(0, $cols, ' '))
                . $this->options[self::VERTICAL_LINE];
        }

        // text
        for ($i = 0; $i < count($text); $i++) {
            $length = strlen(strip_tags($text[$i], $this->options[self::ALLOWED_TAGS]));
            $left   = $this->options[self::CENTERED]
                ? $this->options[self::PADDING_LEFT_RIGHT] + (int)floor(($max - $length) / 2)
                : $this->options[self::PADDING_LEFT_RIGHT];
            $right  = $this->options[self::CENTERED]
                ? $this->options[self::PADDING_LEFT_RIGHT] + (int)ceil(($max - $length) / 2)
                : $cols - $length - $this->options[self::PADDING_LEFT_RIGHT];
            $lines[] = $this->options[self::VERTICAL_LINE]
                . implode('', array_fill(0, $left, ' '))
                . $text[$i]
                . implode('', array_fill(0, $right, ' '))
                . $this->options[self::VERTICAL_LINE];
        }

        // padding bottom
        for ($i = 0; $i < $this->options[self::PADDING_TOP_BOTTOM]; $i++) {
            $lines[] = $this->options[self::VERTICAL_LINE]
                . implode('', array_fill(0, $cols, ' ')) . $this->options[self::VERTICAL_LINE];
        }

        // bottom
        $lines[] = $this->options[self::BOTTOM_LEFT]
            . implode('', array_fill(0, $cols, $this->options[self::HORIZONTAL_LINE]))
            . $this->options[self::BOTTOM_RIGHT];

        // bottom margin
        for ($i = 0; $i < $this->options[self::MARGIN_BOTTOM]; $i++) {
            $lines[] = '';
        }

        $this->stream->write(implode("\n", $lines));
    }
1342985
protected function renderText($text, $status = 200, $minetype = 'html') {
		// Check if a output action has be already performed
		$this->_checkIfPerformed();

		// Set template settings
		$this->useTemplate(false, $status, $minetype);

		return $text;
	}
1007413
public function text($text) {

        if(false === is_string($text)) {
            return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($text)), E_USER_ERROR);
        }

    	$this -> text = $text;

    	return $this;
    }
548625
public function loadGrammar(string $text): Grammar
    {
        $this->symbols = [];
        $this->inline = [];
        $this->regexpMap = [];
        $this->defines = [];
        $this->whitespaces = [];
        $this->modifiers = null;

        try {
            /** @var Rule[] $rules */
            $rules = $this->parser->parse($text, $this->actions)->made();

            /** @var int[] $subject_rules_count */
            $subject_rules_count = [];
            /** @var int[] $inline_ref_count */
            $inline_ref_count = [];
            /** @var Rule[] $inline_ref_rule */
            $inline_ref_rule = [];

            $non_terminal_is_hidden = [];
            $hidden_non_terminals = [];

            foreach ($rules as $rule) {
                $subject = $rule->getSubject();
                $subject_name = $subject->getName();
                $subject_hidden = $subject->isHidden();

                // RegExp tokens cannot be non-terminals in the same time
                // since there is no anonymous RegExp terminals
                if (isset($this->regexpMap[$subject_name])) {
                    throw new GrammarException(
                        "Symbol `$subject_name` defined as non-terminal and as regexp terminal in the same time"
                    );
                }

                if (isset($non_terminal_is_hidden[$subject_name])) {
                    if ($subject_hidden !== $non_terminal_is_hidden[$subject_name]) {
                        throw new GrammarException(
                            "Symbol `$subject_name` defined both as hidden and as visible"
                        );
                    }
                } else {
                    $non_terminal_is_hidden[$subject_name] = $subject_hidden;
                }

                $subject_rules_count[$subject_name] = ($subject_rules_count[$subject_name] ?? 0) + 1;

                if ($subject_hidden) {
                    $hidden_non_terminals[$subject_name] = true;
                }

                foreach ($rule->getDefinition() as $symbol) {
                    $name = $symbol->getName();
                    if (isset($this->inline[$name])) {
                        $inline_ref_count[$name] = ($inline_ref_count[$name] ?? 0) + 1;

                        // it is needed in case of the only reference,
                        // so array of an subject is not needed
                        $inline_ref_rule[$name] = $rule;
                    }
                }
            }

            foreach ($hidden_non_terminals as $name => $_) {
                if (isset($this->symbols[$name][false])) {
                    $this->symbols[$name][false]->setIsHidden(true);
                }
            }

            // Convert non-terminals defined only once with inline tokens
            // `Subject: "inline"`
            // into fixed terminals
            $fixed = [];
            foreach ($inline_ref_count as $inline_token => $ref_count) {
                if (1 !== $ref_count) {
                    continue;
                }

                $rule = $inline_ref_rule[$inline_token];
                if (null === $rule->getTag() && 1 === count($rule->getDefinition())) {
                    $subject = $rule->getSubject();
                    $name = $subject->getName();

                    if (1 !== $subject_rules_count[$name]) {
                        continue;
                    }

                    // remove rule
                    $key = array_search($rule, $rules, true);
                    if (false !== $key) {
                        unset($rules[$key]);
                    }

                    // remove inline
                    unset($this->inline[$inline_token]);

                    // make terminal
                    $subject->setIsTerminal(true);
                    if (isset($this->symbols[$name][!$subject->isHidden()])) {
                        $this->symbols[$name][!$subject->isHidden()]->setIsTerminal(true);
                    }

                    $fixed[$name] = $inline_token;
                }
            }

            return new Grammar(
                $rules,
                $this->inline,
                $fixed,
                $this->regexpMap,
                $this->whitespaces,
                $this->defines,
                $this->modifiers ?? ''
            );
        } catch (UnknownCharacterException | UnexpectedInputAfterEndException | UnexpectedTokenException $e) {
            throw new GrammarException(
                'Cannot parse grammar: ' . $e->getMessage() . ' at offset ' . $e->getOffset(),
                0,
                $e
            );
        } catch (AbortedException $e) {
            for ($inner = $e; $inner; $inner = $inner->getPrevious()) {
                if ($inner instanceof GrammarException || $inner instanceof InternalException) {
                    throw $inner;
                }
            }
            throw new InternalException('Failure while parsing your grammar text', 0, $e);
        } finally {
            $this->symbols = null;
            $this->inline = null;
            $this->regexpMap = null;
            $this->defines = null;
            $this->whitespaces = null;
            $this->modifiers = null;
        }
    }
1049021
protected function _parseTags(&$text)
    {
        $tags = '';

        $matches = array();
        if(preg_match_all('#<ktml:style\s+src="([^"]+)"(.*)\/>#siU', $text, $matches))
        {
            foreach(array_unique($matches[1]) as $key => $match)
            {
                //Set required attributes
                $attribs = array(
                    'src' => $match
                );

                $attribs = array_merge($this->parseAttributes( $matches[2][$key]), $attribs);
                $tags .= $this->_renderTag($attribs);
            }

            $text = str_replace($matches[0], '', $text);
        }

        $matches = array();
        if(preg_match_all('#<style(.*)>(.*)<\/style>#siU', $text, $matches))
        {
            foreach($matches[2] as $key => $match)
            {
                $attribs = $this->parseAttributes( $matches[1][$key]);
                $tags .= $this->_renderTag($attribs, $match);
            }

            $text = str_replace($matches[0], '', $text);
        }

        return $tags;
    }
1146713
public function asHtml($text)
    {
        $stream = StreamFactory::string($text);
        return new Response($stream, self::OK, ['Content-Type' => 'text/html']);
    }
1250607
public function clientOnPageRender($text)
    {
        $Eresus = Eresus_CMS::getLegacyKernel();

        preg_match_all('/\$\(Menus:(.+)?\)/Usi', $text, $menus, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
        if (count($menus))
        {
            /** @var TClientUI $page */
            $page = Eresus_Kernel::app()->getPage();
            $page->linkStyles($this->getCodeURL() . 'client/menus.css');
            $page->linkJsLib('jquery');
            $page->linkScripts($this->getCodeURL() . 'client/menus.js');

            $delta = 0;

            $relative = substr($Eresus->request['url'], strlen($Eresus->root), 5);

            if ($relative && $relative != 'main/')
            {
                array_shift($this->ids);
            }

            /** @var Menus_Entity_Table_Menu $table */
            $table = ORM::getTable($this, 'Menu');
            for ($i = 0; $i < count($menus); $i++)
            {
                $entity = $table->findByName($menus[$i][1][0]);
                if ($entity && $entity->active)
                {
                    $menu = new Menus_Menu($Eresus, $page, $entity, $this->ids);
                    $html = $menu->render();
                    $text = substr_replace($text, $html, $menus[$i][0][1] + $delta, strlen($menus[$i][0][0]));
                    $delta += strlen($html) - strlen($menus[$i][0][0]);
                }
            }
        }
        return $text;
    }
151295
protected function runSpanGamut($text) {
		foreach ($this->span_gamut as $method => $priority) {
			$text = $this->$method($text);
		}

		return $text;
	}
371650
public function render($text, $skin) {
        if ($this->renderer === null) {
            throw new ParserException('Renderer not set');
        }

        $tokenList = $this->parse($text);

        return $this->renderer->render($tokenList, $skin);
    }
1192567
public function write($string)
    {
        $this->valideAttach()->valideWrite();
        if (($stream = fwrite($this->stream, $string)) === false) {
            throw new \RuntimeException('An error has occurred.');
        }

        return $stream;
    }
524068
protected function _replaceTags(&$text)
    {
        if (!empty($this->_stripped_tags)) {
            $text = str_replace($this->_stripped_tags[0], $this->_stripped_tags[1], $text);
        }
    }
77324
public function write(&$text)
    {
        //Parse the script information
        $styles = $this->_parseStyles($text);

        //Prepend the script information
        $text = $styles.$text;

        return $this;
    }
593237
public function write(&$text)
    {
        $text = str_replace(
            array_keys($this->_alias_write),
            array_values($this->_alias_write),
            $text);

        return $this;
    }
1228064
public static function _text($text, $values = array()) {
		_t($text, static::getDomain(), is_array($values) ? $values : array_slice(func_get_args(), 1));
	}
280006
public function dontSeeInShellOutput($text)
    {
        $this->debug($this->output);
        \PHPUnit\Framework\Assert::assertNotContains($text, $this->output);
    }
863490
private function tag_text($text)
	{
		if($this->current_tag instanceof Node_Container_Tag)
		{
			$accepted_children = $this->bbcodes[$this->current_tag->tag()]->accepted_children();

			if(!empty($accepted_children) && !in_array('text_node', $accepted_children))
				return;
		}

		$this->current_tag->add_child(new Node_Text($text));
	}
601431
protected function onSetText(string $text): void
    {
        parent::onSetText($text);

        $this->isInvalid = false;
        $this->value = null;

        if ($this->hasError()) {
            return;
        }

        if ($this->isEmpty()) {
            return;
        }

        $this->value = Url::tryParse($text);

        if ($this->value === null) {
            $this->setError('Invalid value');
            $this->isInvalid = true;
        }
    }