From d5bf6922334c7322ca6e44743e02bdc5f5853730 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 15 Sep 2020 12:52:49 +0200 Subject: [PATCH] Add HtmlOutputNodePre::guessHighlighter() This nicely contains the guessing logic within a single function, improving readability. --- .../output/node/HtmlOutputNodePre.class.php | 95 +++++++++++-------- 1 file changed, 54 insertions(+), 41 deletions(-) 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. * -- 2.20.1