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:
authorStefan Tatschner <stefan@sevenbyte.org>2014-12-03 17:27:31 +0300
committerStefan Tatschner <stefan@sevenbyte.org>2015-01-15 15:41:11 +0300
commitbf079c24afb8ad2991a4eaf60a71a7bc45dd775d (patch)
treeed6317f84473ea68ef9444b0a2736f305f0a2b75 /app/helpers/blob_helper.rb
parent377ae460056bb2a4e5824c4f7a3bbcb481e3e38b (diff)
Replace highlight.js with rouge-fork rugments
I decided to create a fork of rouge as rouge lacks a HTML formatter with the required options such as wrapping a line with <span> tags. Furthermore I was not really convinced about the clarity of rouge's source code. Rugments 1.0.0beta3 for now only includes some basic linting and a new HTML formatter. Everything else should behave the same.
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