Module: Redmine::SyntaxHighlighting::Rouge
- Defined in:
- lib/redmine/syntax_highlighting.rb
Defined Under Namespace
Classes: CustomHTMLLinewise
Class Method Summary collapse
- .filename_supported?(filename) ⇒ Boolean
-
.highlight_by_filename(text, filename) ⇒ Object
Highlights
text
as the content offilename
Should not return line numbers nor outer pre tag. -
.highlight_by_language(text, language) ⇒ Object
Highlights
text
usinglanguage
syntax Should not return outer pre tag. - .language_supported?(language) ⇒ Boolean
Class Method Details
.filename_supported?(filename) ⇒ Boolean
113 114 115 |
# File 'lib/redmine/syntax_highlighting.rb', line 113 def filename_supported?(filename) !::Rouge::Lexer.guesses(:filename => filename).empty? end |
.highlight_by_filename(text, filename) ⇒ Object
Highlights text
as the content of filename
Should not return line numbers nor outer pre tag
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/redmine/syntax_highlighting.rb', line 88 def highlight_by_filename(text, filename) # TODO: Delete the following workaround for #30434 and # test_syntax_highlight_should_normalize_line_endings in # application_helper_test.rb when Rouge is improved to # handle CRLF properly. # See also: https://github.com/jneen/rouge/pull/1078 text = text.gsub(/\r\n?/, "\n") lexer =::Rouge::Lexer.guess(:source => text, :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
103 104 105 106 107 |
# File 'lib/redmine/syntax_highlighting.rb', line 103 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
109 110 111 |
# File 'lib/redmine/syntax_highlighting.rb', line 109 def language_supported?(language) find_lexer(language.to_s.downcase) ? true : false end |