From d4a0c9e1f3516794f22b6f07cc6d470b80f8e4dc Mon Sep 17 00:00:00 2001
From: dysonreturns <173946744+dysonreturns@users.noreply.github.com>
Date: Wed, 18 Dec 2024 15:29:25 -0800
Subject: [PATCH 1/2] fix(ruby): stricter block params, allowing bitwise OR
---
src/languages/ruby.js | 24 +++++++++++++-----------
test/markup/ruby/blocks.expect.txt | 3 +++
test/markup/ruby/blocks.txt | 3 +++
3 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/src/languages/ruby.js b/src/languages/ruby.js
index 91b2cb527d..d060da83de 100644
--- a/src/languages/ruby.js
+++ b/src/languages/ruby.js
@@ -243,6 +243,16 @@ export default function(hljs) {
]
};
+
+ const BLOCK_PARAMS = {
+ className: 'params',
+ begin: /(do|\{)\s\|(?!=)/,
+ end: /\|/,
+ excludeBegin: true,
+ excludeEnd: true,
+ keywords: RUBY_KEYWORDS,
+ };
+
const INCLUDE_EXTEND = {
match: [
/(include|extend)\s+/,
@@ -326,7 +336,9 @@ export default function(hljs) {
METHOD_DEFINITION,
{
// swallow namespace qualifiers before symbols
- begin: hljs.IDENT_RE + '::' },
+ begin: hljs.IDENT_RE + '::'
+ },
+ BLOCK_PARAMS,
{
className: 'symbol',
begin: hljs.UNDERSCORE_IDENT_RE + '(!|\\?)?:',
@@ -348,15 +360,6 @@ export default function(hljs) {
className: "variable",
begin: '(\\$\\W)|((\\$|@@?)(\\w+))(?=[^@$?])' + `(?![A-Za-z])(?![@$?'])`
},
- {
- className: 'params',
- begin: /\|(?!=)/,
- end: /\|/,
- excludeBegin: true,
- excludeEnd: true,
- relevance: 0, // this could be a lot of things (in other languages) other than params
- keywords: RUBY_KEYWORDS
- },
{ // regexp container
begin: '(' + hljs.RE_STARTERS_RE + '|unless)\\s*',
keywords: 'unless',
@@ -398,7 +401,6 @@ export default function(hljs) {
SUBST.contains = RUBY_DEFAULT_CONTAINS;
PARAMS.contains = RUBY_DEFAULT_CONTAINS;
-
// >>
// ?>
const SIMPLE_PROMPT = "[>?]>";
diff --git a/test/markup/ruby/blocks.expect.txt b/test/markup/ruby/blocks.expect.txt
index b44cd5ab8f..1fdfdaa6eb 100644
--- a/test/markup/ruby/blocks.expect.txt
+++ b/test/markup/ruby/blocks.expect.txt
@@ -5,3 +5,6 @@
names |= users.map do |user|
user.name
end
+
+bitwise_or = 1 | 2
+not_registered_as_param
diff --git a/test/markup/ruby/blocks.txt b/test/markup/ruby/blocks.txt
index f9cda6d09a..e73964f02b 100644
--- a/test/markup/ruby/blocks.txt
+++ b/test/markup/ruby/blocks.txt
@@ -5,3 +5,6 @@ end
names |= users.map do |user|
user.name
end
+
+bitwise_or = 1 | 2
+not_registered_as_param
From 5e2eaf09e338a8fad3d3f8c2e6dabc082bcc3e3e Mon Sep 17 00:00:00 2001
From: dysonreturns <173946744+dysonreturns@users.noreply.github.com>
Date: Wed, 18 Dec 2024 15:39:38 -0800
Subject: [PATCH 2/2] docs: update changelog
---
CHANGES.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGES.md b/CHANGES.md
index 82b956d9e0..498bedb6d9 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -7,6 +7,7 @@ CAVEATS / POTENTIALLY BREAKING CHANGES
Core Grammars:
+- fix(ruby) correct bitwise OR(|) highlighting
- fix(rust) - adds emoji support in single quote strings [joshgoebel][]
- fix(apache) - support line continuation via `\` [Josh Goebel][]
- fix(makefile) - allow strings inside `$()` expressions [aneesh98][]