Skip to content

bug(ruby) 'if defined?' is mis-highlighted as a def method #3025

Closed
@TGWolf

Description

@TGWolf

When highlighting ruby code the matching is not correctly matching on 'if defined'

for example:

if defined?(key)

Instead of matching on the 2 keywords IF and DEFINED it instead matches on IF and DEF as keywords then matched INED as a title. The downside to this is the word defined is now in 2 different colours.

I think it is related to the use if def when defining a function in ruby and so it is matching def from the word defined and thinks you have a function called ined.

I am using version 10.5.0 of highlight.

Sample Code:

I am using sunburst.css (although this happens in others and I don't think the css is the issue)

#!/usr/bin/env ruby

require 'rubygems'
require 'gems'
require 'terminal-table'

if defined?(key)
    Gems.configure do |config|
        config.key = key
    end
else
    puts 'Using default gem creds'
end

Activity

joshgoebel

joshgoebel commented on Feb 27, 2021

@joshgoebel
Member

Confirm. Pretty sure our function detection should probably be def\s+ not def\s*.

changed the title [-]Ruby highlighting is miss matching 'if defined'[/-] [+]bug(ruby) 'if defined?' is mis-highlighted as a def method[/+] on Feb 27, 2021
added a commit that references this issue on Mar 30, 2024
e83656c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @joshgoebel@TGWolf

        Issue actions

          bug(ruby) 'if defined?' is mis-highlighted as a def method · Issue #3025 · highlightjs/highlight.js