Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/blob_helper.rb')
-rw-r--r--app/helpers/blob_helper.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb
index 420ac3f77c7..3a282803963 100644
--- a/app/helpers/blob_helper.rb
+++ b/app/helpers/blob_helper.rb
@@ -1,10 +1,19 @@
module BlobHelper
- def highlightjs_class(blob_name)
- if no_highlight_files.include?(blob_name.downcase)
- 'no-highlight'
- else
- blob_name.downcase
+ def highlight(blob_name, blob_content, nowrap = false)
+ formatter = Rugments::Formatters::HTML.new(
+ nowrap: nowrap,
+ cssclass: 'code highlight',
+ lineanchors: true,
+ lineanchorsid: 'LC'
+ )
+
+ begin
+ lexer = Rugments::Lexer.guess(filename: blob_name, source: blob_content)
+ rescue Rugments::Lexer::AmbiguousGuess
+ lexer = Rugments::Lexers::PlainText
end
+
+ formatter.format(lexer.lex(blob_content)).html_safe
end
def no_highlight_files