Module: RSpec::Core::Formatters::SyntaxHighlighter::CodeRayImplementation

Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/syntax_highlighter.rb

Constant Summary collapse

RESET_CODE =
"\e[0m"

Class Method Summary collapse

Class Method Details

.highlight_syntax(lines) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/syntax_highlighter.rb', line 64

def self.highlight_syntax(lines)
  highlighted = begin
    CodeRay.encode(lines.join("\n"), :ruby, :terminal)
  rescue Support::AllExceptionsExceptOnesWeMustNotRescue
    return lines
  end

  highlighted.split("\n").map do |line|
    line.sub(/\S/) { |char| char.insert(0, RESET_CODE) }
  end
end