Shortcode to quicker format text as HTML.

@param string $text text to be converted.

@return string the formatted text.
555658
public function shortCode($text)
    {
        /* Needs PHP 7
        $patternsAndCallbacks = [
            "/\[(FIGURE)[\s+](.+)\]/" => function ($match) {
                return self::ShortCodeFigure($matches[2]);
            },
            "/(```([\w]*))\n([^`]*)```[\n]{1}/s" => function ($match) {
                return $this->syntaxHighlightGeSHi($matches[3], $matches[2]);
            },
        ];

        return preg_replace_callback_array($patternsAndCallbacks, $text);
        */

        $patterns = [
            "/\[(FIGURE)[\s+](.+)\]/",
            //'/\[(YOUTUBE) src=(.+) width=(.+) caption=(.+)\]/',
            "/\[(YOUTUBE)[\s+](.+)\]/",
            "/\[(CODEPEN)[\s+](.+)\]/",
            "/\[(ASCIINEMA)[\s+](.+)\]/",
            "/\[(BOOK)[\s+](.+)\]/",
            //"/(```)([\w]*)\n([.]*)```[\n]{1}/s",
            "/(```)([\w]*)\n(.*?)```\n/s",
            '/\[(INFO)\]/',
            '/\[(\/INFO)\]/',
            '/\[(WARNING)\]/',
            '/\[(\/WARNING)\]/',
        ];

        return preg_replace_callback(
            $patterns,
            function ($matches) {
                switch ($matches[1]) {
                    case "FIGURE":
                        return self::shortCodeFigure($matches[2]);
                    break;

                    case "YOUTUBE":
                        return self::shortCodeYoutube($matches[2]);
                    break;

                    case "CODEPEN":
                        return self::shortCodeCodepen($matches[2]);
                    break;

                    case "ASCIINEMA":
                        return self::shortCodeAsciinema($matches[2]);
                    break;

                    case "BOOK":
                        return self::shortCodeBook($matches[2]);
                    break;

                    case "```":
                        //return $this->syntaxHighlightGeSHi($matches[3], $matches[2]);
                        return $this->syntaxHighlightJs($matches[3], $matches[2]);
                    break;

                    case 'INFO':
                        return <<<EOD
<div class="info">
    <span class="icon fa-stack fa-lg">
        <i class="fa fa-circle fa-stack-2x"></i>
        <i class="fa fa-info fa-stack-1x fa-inverse" aria-hidden="true"></i>
    </span>
    <div markdown=1>
EOD;
                        break;

                    case 'WARNING':
                        return <<<EOD
<div class="warning">
    <span class="icon fa-stack fa-lg">
        <i class="fa fa-circle fa-stack-2x"></i>
        <i class="fa fa-exclamation-triangle fa-stack-1x fa-inverse" aria-hidden="true"></i>
    </span>
    <div markdown=1>
EOD;
                        break;

                    case '/INFO':
                    case '/WARNING':
                        return "</div></div>";
                        break;

                    default:
                        return "{$matches[1]} is unknown shortcode.";
                }
            },
            $text
        );
    }
1203016
public function writeRawData($text)
    {
        if (is_array($text)) {
            $text = implode("\n", $text);
        }

        if (method_exists($this, 'writeRaw')) {
            return $this->writeRaw(htmlspecialchars($text));
        }

        return $this->text($text);
    }
978586
public static function convert($text)
    {
        static $parser;

        if (empty($parser)) {
            $parser = new MarkdownExtraExtended();
        }

        return $parser->transform($text);
    }
574183
public function format($text)
    {
        $lines = explode("\n", $text);
        foreach ($lines as &$line) {
            $line = ((string) $this->quote)
                  . str_repeat(' ', $this->indent * $this->indentWidth) 
                  . $line;
        }
        return Colors::colorize(implode("\n", $lines), $this->fgColor, $this->bgColor);
    }
1128955
public static function ctype_punct($text)
    {
        $text = self::convert_int_to_char_for_ctype($text);

        return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text);
    }
393865
protected function renderText($text)
	{
		if ($this->enableNewlines) {
			return preg_replace("/(  \n|\n)/", "\\\\\\\\\n", $this->escapeLatex($text[1]));
		} else {
			return parent::renderText($text);
		}
	}
1291230
public function text($text = '')
    {
        $msg = array(
            'ToUserName'   => $this->getRevFrom(),
            'FromUserName' => $this->getRevTo(),
            'MsgType'      => self::MSGTYPE_TEXT,
            'Content'      => $this->_auto_text_filter($text),
            'CreateTime'   => time(),
        );
        $this->Message($msg);
        return $this;
    }
1242529
public function text($text)
    {
        foreach ($this->_data as $macros => $value) {
            $macros = '{' . $macros . '}';
            $text   = preg_replace('#' . $macros . '#ius', $value, $text);
        }

        return $text;
    }
960849
public static function shorten(string $text = '', ?int $charCount = null, bool $fullWords = true,
                                   string $suffix = '...'): string
    {
        $text = StripTags::strip($text);
        $text = \htmlspecialchars_decode((string)$text, ENT_COMPAT | ENT_HTML5);
        $text = \trim(\preg_replace('/\s+/', ' ', $text));

        if ($charCount === null || \mb_strlen($text, 'UTF-8') <= $charCount) {
            return $text;
        }

        if ($fullWords === true) {
            $shortened = \mb_substr($text, 0, $charCount, 'UTF-8');
            while (!\in_array(\mb_substr($shortened, -1, 1, 'UTF-8'), static::$wordEndingChars)) {
                $shortened = \mb_substr($shortened, 0, -1, 'UTF-8');
            }
        }
        if ($fullWords !== true) {
            $shortened = \mb_substr($text, 0, $charCount, 'UTF-8');
        }

        while (\in_array(\mb_substr($shortened, -1, 1, 'UTF-8'), static::$wordEndingChars)) {
            $shortened = \mb_substr($shortened, 0, -1, 'UTF-8');
        }

        return $shortened.$suffix;
    }
455952
public function shortCode($text)
    {
        $patterns = [
            '/\[(FIGURE)[\s+](.+)\]/',
            '/\[(BASEURL)\]/',
            '/\[(RELURL)\]/',
            '/\[(ASSET)\]/',
        ];

        return preg_replace_callback(
            $patterns,
            function ($matches) {
                switch ($matches[1]) {

                    case 'FIGURE':
                        return CTextFilter::shortCodeFigure($matches[2]);
                        break;

                    case 'BASEURL':
                        return CTextFilter::shortCodeBaseurl();
                        break;

                    case 'RELURL':
                        return CTextFilter::shortCodeRelurl();
                        break;

                    case 'ASSET':
                        return CTextFilter::shortCodeAsset();
                        break;

                    default:
                        return "{$matches[1]} is unknown shortcode.";
                }
            },
            $text
        );
    }
806436
public static function nameToHtmlAttribute(string $text): string
    {
        if (isset(self::$textToHtmlAttributeCache[$text])) {
            return self::$textToHtmlAttributeCache[$text];
        }

        return self::$textToHtmlAttributeCache[$text] = preg_replace('/[^a-zA-Z0-9\_]+/', '_', $text);
    }
1146713
public function asHtml($text)
    {
        $stream = StreamFactory::string($text);
        return new Response($stream, self::OK, ['Content-Type' => 'text/html']);
    }
1276882
public static function cleanText(&$text)
    {
        $text = preg_replace("'<script[^>]*>.*?</script>'si", '', $text);
        $text = preg_replace('/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text);
        $text = preg_replace('/<!--.+?-->/', '', $text);
        $text = preg_replace('/{.+?}/', '', $text);
        $text = preg_replace('/&nbsp;/', ' ', $text);
        $text = preg_replace('/&amp;/', ' ', $text);
        $text = preg_replace('/&quot;/', ' ', $text);
        $text = strip_tags($text);
        $text = htmlspecialchars($text, ENT_COMPAT, 'UTF-8');

        return $text;
    }
1037191
public function transform( $text, $options = null )
    {
        if ( null !== $options )
        {
            $this->setOptions( $options );
        }

        $parser = $this->extraEnabled
                ? new MarkdownExtraParser
                : new MarkdownParser;
        $parsed = $parser->transformMarkdown( $text );

        if ( ! empty( $this->linkTarget ) )
        {
            $parsed = preg_replace(
                '#<(a|form)((\s[^>]*)?)>(.*?)</\\1>#',
                '<$1 target="' . htmlspecialchars( $this->linkTarget ) . '"$2>$4</$1>',
                $parsed
            );
        }

        if ( $this->stripScripts )
        {
            $parsed = preg_replace(
                '#<script(\s[^>]*)?>.*?</script>#',
                '',
                $parsed
            );
        }

        return $parsed;
    }
683955
public function makeHtml($text)
    {
        $this->_footnotes = array();
        $this->_definitions = array();
        $this->_holders = array();
        $this->_uniqid = md5(uniqid());
        $this->_id = 0;
        usort($this->blockParsers, function ($a, $b) {
            return $a[1] < $b[1] ? -1 : 1;
        });
        foreach ($this->blockParsers as $parser) {
            list ($name) = $parser;
            if (isset($parser[2])) {
                $this->_parsers[$name] = $parser[2];
            } else {
                $this->_parsers[$name] = array($this, 'parseBlock' . ucfirst($name));
            }
        }
        $text = $this->initText($text);
        $html = $this->parse($text); 
        $html = $this->makeFootnotes($html);
        $html = $this->optimizeLines($html);
        return $this->call('makeHtml', $html);
    }
752630
protected function createDocumentWithHtml($text)
    {
        $dom = new \DOMDocument();
        $dom->loadHTML(mb_convert_encoding(
            $this->purifier->purify(mb_convert_encoding($text, $this->config->getEncoding(), mb_detect_encoding($text))),
            'HTML-ENTITIES',
            $this->config->getEncoding()
        ));

        return $dom;
    }
924536
public static function colorify($text)
    {
        $htmldecoded = htmlspecialchars($text);
        $boldSqBracket = preg_replace('/\[([a-zA-Z]+)\]/', '[<span style="color: #000; font-weight: bold;">${1}</span>]', $htmldecoded);
        $boldBracket = preg_replace('/\{([a-zA-Z_ ]+)\}/', '{<span style="color: #000; font-weight: bold;">${1}</span>}', $boldSqBracket);
        return str_replace(self::$_search, self::$_replace, $boldBracket);
    }