From a5b4193796295a1149dbc23710f3b575186e30bb Mon Sep 17 00:00:00 2001 From: WaterXiao-git Date: Sat, 27 Jun 2026 15:11:58 +0800 Subject: [PATCH] fix(bash): Add consistent highlighting for command-line options Add an OPTION mode to match short (-o) and long (--option=value) command-line flags, ensuring they are highlighted consistently across continuation lines instead of being partially matched by keyword or path patterns. Closes #4288 --- src/languages/bash.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/languages/bash.js b/src/languages/bash.js index 44f9beba97..6773259705 100644 --- a/src/languages/bash.js +++ b/src/languages/bash.js @@ -145,6 +145,14 @@ export default function(hljs) { // to consume paths to prevent keyword matches inside them const PATH_MODE = { match: /(\/[a-z._-]+)+/ }; + // Match command-line options (short: -o, long: --option, --option=value) + // to ensure consistent highlighting across continuation lines. + const OPTION = { + className: 'attr', + begin: /(?:^|\s)--?\w[\w-]*(?:=?\S*)?\s*/, + relevance: 0 + }; + // http://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html const SHELL_BUILT_INS = [ "break", @@ -397,6 +405,7 @@ export default function(hljs) { COMMENT, HERE_DOC, PATH_MODE, + OPTION, QUOTE_STRING, ESCAPED_QUOTE, APOS_STRING,