From: Tim Düsterhus Date: Tue, 15 Sep 2020 11:39:31 +0000 (+0200) Subject: Extend automated guessing logic of highlighters X-Git-Tag: 5.3.0_Beta_1~24^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a98125841352c002e846723f9d5df5caf6420aec;p=GitHub%2FWoltLab%2FWCF.git Extend automated guessing logic of highlighters --- 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 84a3d9895a..8a6f8b46ad 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 @@ -157,50 +157,89 @@ class HtmlOutputNodePre extends AbstractHtmlOutputNode { * @return string */ public function guessHighlighter($content) { - $highlighter = ''; + // PHP at the beginning is almost surely PHP. + if (mb_strpos($content, 'match($content)) { + return 'python'; } - else if (mb_strpos($content, 'match($content)) { + return 'bash'; } - else if ( mb_strpos($content, 'SELECT') === 0 - || mb_strpos($content, 'UPDATE') === 0 - || mb_strpos($content, 'INSERT') === 0 - || mb_strpos($content, 'DELETE') === 0) { - $highlighter = 'sql'; + + if ( mb_strpos($content, 'FROM') === 0 + && mb_strpos($content, "RUN") !== false) { + return 'docker'; } - else if (mb_strpos($content, 'import java.') !== false) { - $highlighter = 'java'; + + if ( mb_stripos($content, "RewriteRule") !== false + || mb_stripos($content, "RewriteEngine On") !== false + || mb_stripos($content, "AuthUserFile") !== false) { + return 'apacheconf'; } - else if ( mb_strpos($content, "---") !== false - && mb_strpos($content, "\n+++") !== false) { - $highlighter = 'diff'; + + if (mb_strpos($content, '\\documentclass') !== false) { + return 'latex'; } - else if (mb_strpos($content, "\n#include ") !== false) { - $highlighter = 'c'; + + // PHP somewhere later might not necessarily be PHP, it could also be + // a .patch or a Dockerfile. + if (mb_strpos($content, 'match($content)) { - $highlighter = 'bash'; + + if (mb_strpos($content, '