highlightjs / highlightjs/highlight.js

(Ruby) #{} substitution shouldn't be highlighted in single quotes

Open
#3,676 3 comments 0 reactions 1 assignee Claimed by @kingflamez View on GitHub
bug good first issue help welcome language
Dominant language
JavaScript
Stars
25k
Forks
3.8k
Avg merge
11h 35m
Merged PRs (30d)
3

Description

**Describe the issue**
In Ruby, single quote and double quote strings work differently:

> In addition to disabling interpolation [(`#{}` syntax)], single-quoted strings also disable all escape sequences except for the single-quote (`\'`) and backslash (`\\`).

https://docs.ruby-lang.org/en/3.1/syntax/literals_rdoc.html#label-Strings

But in ruby.js, they are implemented identically

https://github.com/highlightjs/highlight.js/blob/9c49a4298a981e960b6d112c746d998d51e1d1e8/src/languages/ruby.js#L132-L139

which leads it to incorrectly highlight `#{}` substitutions in single quoted strings which actually have no effect, they are just literal `#{}` characters (in the "`github`" theme):

Screenshot 2022-12-11 at 19 00 50

instead of highlighting it as a string, like it does if we remove the `#`:

Screenshot 2022-12-11 at 19 01 01

**Which language seems to have the issue?**
Ruby

**Are you using `highlight` or `highlightAuto`?**
N/A

**Expected behavior**
Single and double quoted strings should have separate highlighting rules for Ruby.

**Additional context**
https://docs.ruby-lang.org/en/3.1/syntax/literals_rdoc.html#label-Strings

Unrelated, but for double quoted strings, that page also lists a couple interpolation syntax shorthands that are not implemented in the highlight.js grammar:

> You can also use `#@foo`, `#@@foo` and `#$foo` as a shorthand for, respectively, `#{ @foo }`, `#{ @@foo }` and `#{ $foo }`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.