diff options
author | Mark Chao <mchao@gitlab.com> | 2018-09-06 12:34:25 +0800 |
---|---|---|
committer | Mark Chao <mchao@gitlab.com> | 2018-10-30 15:44:55 +0800 |
commit | 39ae9a59a59615092fbef189466f37c34f4a7fb1 (patch) | |
tree | c8611265f8fb290cbce92f04cadb593b531165ee /lib/gitlab/highlight.rb | |
parent | 32f9cf8ce3dd337bf3b1683c5872171c253f0d27 (diff) | |
download | gitlab-ce-39ae9a59a59615092fbef189466f37c34f4a7fb1.tar.gz |
Make Highlight accept language param
This replaces the repository param.
This allows more flexiblity as sometimes we have highlight content
not related to repository. Sometimes we know ahead of time the language
of the content. Lastly language determination seems better fit as a
logic in the Blob class.
`repository` param is only used to determine the language, which seems
to be the responsiblity of Blob.
Diffstat (limited to 'lib/gitlab/highlight.rb')
-rw-r--r-- | lib/gitlab/highlight.rb | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index 83095acc528..d28223194cc 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -5,16 +5,16 @@ module Gitlab TIMEOUT_BACKGROUND = 30.seconds TIMEOUT_FOREGROUND = 3.seconds - def self.highlight(blob_name, blob_content, repository: nil, plain: false) - new(blob_name, blob_content, repository: repository) + def self.highlight(blob_name, blob_content, language: nil, plain: false) + new(blob_name, blob_content, language: language) .highlight(blob_content, continue: false, plain: plain) end attr_reader :blob_name - def initialize(blob_name, blob_content, repository: nil) + def initialize(blob_name, blob_content, language: nil) @formatter = Rouge::Formatters::HTMLGitlab - @repository = repository + @language = language @blob_name = blob_name @blob_content = blob_content end @@ -36,11 +36,9 @@ module Gitlab private def custom_language - language_name = @repository && @repository.gitattribute(@blob_name, 'gitlab-language') + return nil unless @language - return nil unless language_name - - Rouge::Lexer.find_fancy(language_name) + Rouge::Lexer.find_fancy(@language) end def highlight_text(text, continue: true, plain: false) |