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][] 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