highlight.js icon indicating copy to clipboard operation
highlight.js copied to clipboard

(ruby) Syntax highlight fails with `%r/` Ruby expression

Open j-erasmus opened this issue 8 months ago • 2 comments

Describe the issue Ruby syntax highlight fails with %r Ruby expression. See screenshot:

Image

Which language seems to have the issue?

Ruby

Are you using highlight or highlightAuto?

  • highlight

...

Sample Code to Reproduce

  # Validations
  validates :creator, presence: true, on: :create
  validates :description, length: { maximum: 2000 }, allow_blank: true
  validates :ci_config_path,
    format: { without: %r{(\.{2}|\A/)},
              message: N_('cannot include leading slash or directory traversal.') },
    length: { maximum: 255 },
    allow_blank: true
  validates :name,
    presence: true,
    length: { maximum: 255 }
  validates :path,
    presence: true,
    project_path: true,
    length: { maximum: 255 }

Expected behavior Syntax highlighting should work as expected after %r/ Ruby expression

Additional context

Full example file can be found here: https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/project.rb

j-erasmus avatar Jun 10 '25 09:06 j-erasmus

Thanks for the report. A PR would be welcome.

joshgoebel avatar Jun 12 '25 02:06 joshgoebel

@joshgoebel FYI, I've opened a PR to fix it: https://github.com/highlightjs/highlight.js/pull/4286

j-erasmus avatar Jun 27 '25 09:06 j-erasmus