From e22bb0545decefdd081b5dc241431859f47d95f9 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 14 Apr 2021 17:19:01 -0400 Subject: [PATCH] Make operator highlighting optional --- src/FileType.php | 7 +++++++ src/Row.php | 9 +++++++-- src/Syntax.php | 11 ++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/FileType.php b/src/FileType.php index 27cd61c..fa442e6 100644 --- a/src/FileType.php +++ b/src/FileType.php @@ -18,9 +18,15 @@ class FileType { return match ($ext) { '.sh', '.bash' => Syntax::new( 'Shell', + [ + 'case', 'do', 'done', 'elif', 'else', 'esac', 'fi', 'for', 'function', 'if', 'in', + 'select', 'then', 'time', 'until', 'while', 'declare', + ], + ['set'], slcs: '#', mcs: '', mce: '', + highlightNumbers: false, ), '.php', 'kilo' => Syntax::new( 'PHP', @@ -49,6 +55,7 @@ class FileType { '.css', '.less', '.sass', '.scss' => Syntax::new( 'CSS', slcs: '', + hasCommonOperators: false, ), '.go' => Syntax::new( 'Go', diff --git a/src/Row.php b/src/Row.php index 98219f9..8015c86 100644 --- a/src/Row.php +++ b/src/Row.php @@ -257,7 +257,7 @@ class Row { || $this->highlightString($i, $syntax) || $this->highlightOperators($i, $syntax) || $this->highlightCommonDelimeters($i) - || $this->highlightCommonOperators($i) + || $this->highlightCommonOperators($i, $syntax) || $this->highlightNumber($i, $syntax) ) { continue; @@ -376,8 +376,13 @@ class Row { return $this->highlightWord($i, $opts->operators, Highlight::OPERATOR); } - protected function highlightCommonOperators(int &$i): bool + protected function highlightCommonOperators(int &$i, Syntax $opts): bool { + if ( ! $opts->commonOperators()) + { + return false; + } + return $this->highlightChar( $i, ['+', '-', '*', '/', '<', '^', '>', '%', '=', ':', ',', ';', '&', '~'], diff --git a/src/Syntax.php b/src/Syntax.php index 3d6cb0d..d311b14 100644 --- a/src/Syntax.php +++ b/src/Syntax.php @@ -19,6 +19,7 @@ class Syntax { bool $highlightComments = true, bool $hasCharType = false, bool $highlightCharacters = false, + bool $hasCommonOperators = true, ): self { return new self( @@ -34,12 +35,13 @@ class Syntax { $highlightCharacters, $highlightStrings, $highlightComments, + $hasCommonOperators, ); } public static function default(): self { - return self::new('No filetype', slcs: '', mcs: '', mce: '', highlightNumbers: false, highlightStrings: false); + return self::new('No filetype', slcs: '', mcs: '', mce: '', highlightNumbers: false, highlightStrings: false, hasCommonOperators: false); } private function __construct( @@ -67,6 +69,8 @@ class Syntax { private bool $highlightStrings, /** should we highlight comments? */ private bool $highlightComments, + /** should we highlight common operators? */ + private bool $hasCommonOperators, ) {} public function numbers(): bool @@ -100,4 +104,9 @@ class Syntax { { return $this->highlightComments && strlen($this->singleLineCommentStart) !== 0; } + + public function commonOperators(): bool + { + return $this->hasCommonOperators; + } } \ No newline at end of file