From 586b0b6e5724c79c17f57e04897a1c7d7dead6f6 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 29 Mar 2018 19:29:09 -0400 Subject: [PATCH 1/2] Add bash to text_highlight language list --- include/text.php | 4 ++++ src/Content/Text/BBCode.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/text.php b/include/text.php index 67ce7e65e..311422c57 100644 --- a/include/text.php +++ b/include/text.php @@ -2030,6 +2030,10 @@ function text_highlight($s, $lang) { $lang = 'javascript'; } + if ($lang === 'bash') { + $lang = 'sh'; + } + // @TODO: Replace Text_Highlighter_Renderer_Html by scrivo/highlight.php // Autoload the library to make constants available diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 7d1c42976..d545492bb 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1294,7 +1294,7 @@ class BBCode extends BaseObject { if (in_array(strtolower($match[1]), ['php', 'css', 'mysql', 'sql', 'abap', 'diff', 'html', 'perl', 'ruby', - 'vbscript', 'avrc', 'dtd', 'java', 'xml', 'cpp', 'python', 'javascript', 'js', 'sh']) + 'vbscript', 'avrc', 'dtd', 'java', 'xml', 'cpp', 'python', 'javascript', 'js', 'sh', 'bash']) ) { return text_highlight($match[2], strtolower($match[1])); } From 80b6dc5787a6da176f1906132e8b520b5aa2db43 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 29 Mar 2018 19:29:36 -0400 Subject: [PATCH 2/2] Add fallback to regular code if language doesn't exist --- src/Content/Text/BBCode.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index d545492bb..5b0aa2cff 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1292,13 +1292,17 @@ class BBCode extends BaseObject private static function textHighlightCallback($match) { + // Fallback in case the language doesn't exist + $return = '[code]' . $match[2] . '[/code]'; + if (in_array(strtolower($match[1]), ['php', 'css', 'mysql', 'sql', 'abap', 'diff', 'html', 'perl', 'ruby', 'vbscript', 'avrc', 'dtd', 'java', 'xml', 'cpp', 'python', 'javascript', 'js', 'sh', 'bash']) ) { - return text_highlight($match[2], strtolower($match[1])); + $return = text_highlight($match[2], strtolower($match[1])); } - return $match[0]; + + return $return; } /**