Module: Redmine::SyntaxHighlighting::Rouge

Defined in:
lib/redmine/syntax_highlighting.rb

Overview

Since:

  • 4.0.0

Defined Under Namespace

Classes: CustomHTMLLinewise

Class Method Summary collapse

Class Method Details

.highlight_by_filename(text, filename) ⇒ Object

Highlights text as the content of filename Should not return line numbers nor outer pre tag



78
79
80
81
82
# File 'lib/redmine/syntax_highlighting.rb', line 78

def highlight_by_filename(text, filename)
  lexer =::Rouge::Lexer.guess_by_filename(filename)
  formatter = ::Rouge::Formatters::HTML.new
  ::Rouge.highlight(text, lexer, CustomHTMLLinewise.new(formatter))
end

.highlight_by_language(text, language) ⇒ Object

Highlights text using language syntax Should not return outer pre tag



86
87
88
89
90
# File 'lib/redmine/syntax_highlighting.rb', line 86

def highlight_by_language(text, language)
  lexer =
    find_lexer(language.to_s.downcase) || ::Rouge::Lexers::PlainText
  ::Rouge.highlight(text, lexer, ::Rouge::Formatters::HTML)
end

.language_supported?(language) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/redmine/syntax_highlighting.rb', line 92

def language_supported?(language)
  find_lexer(language.to_s.downcase) ? true : false
end