From: Tim Düsterhus Date: Tue, 15 Sep 2020 10:52:49 +0000 (+0200) Subject: Add HtmlOutputNodePre::guessHighlighter() X-Git-Tag: 5.3.0_Beta_1~24^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d5bf6922334c7322ca6e44743e02bdc5f5853730;p=GitHub%2FWoltLab%2FWCF.git Add HtmlOutputNodePre::guessHighlighter() This nicely contains the guessing logic within a single function, improving readability. --- diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodePre.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodePre.class.php index a546ab6ee8..84a3d9895a 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodePre.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodePre.class.php @@ -108,47 +108,7 @@ class HtmlOutputNodePre extends AbstractHtmlOutputNode { } if (!$highlighter) { - // try to guess highlighter - if (mb_strpos($content, 'match($content)) { - $highlighter = 'bash'; - } - else if (mb_strpos($content, '\\documentclass') !== false) { - $highlighter = 'latex'; - } - else if (mb_strpos($content, '!important;') !== false) { - $highlighter = 'css'; - } + $highlighter = $this->guessHighlighter($content); } $eventData = [ 'highlighter' => $highlighter, @@ -190,6 +150,59 @@ class HtmlOutputNodePre extends AbstractHtmlOutputNode { return WCF::getTPL()->fetch('codeMetaCode'); } + /** + * Returns a likely highlighter for the given content. + * + * @param string $content + * @return string + */ + public function guessHighlighter($content) { + $highlighter = ''; + + if (mb_strpos($content, 'match($content)) { + $highlighter = 'bash'; + } + else if (mb_strpos($content, '\\documentclass') !== false) { + $highlighter = 'latex'; + } + else if (mb_strpos($content, '!important;') !== false) { + $highlighter = 'css'; + } + + return $highlighter; + } + /** * Returns a unique ID for this code block. *