From a98125841352c002e846723f9d5df5caf6420aec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 15 Sep 2020 13:39:31 +0200 Subject: [PATCH] Extend automated guessing logic of highlighters --- .../output/node/HtmlOutputNodePre.class.php | 99 +++++++++++++------ 1 file changed, 69 insertions(+), 30 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 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, '