Commit f736721c authored by Stefan Tatschner's avatar Stefan Tatschner Committed by Stefan Tatschner

Replace Rugments with Rouge

I have mainly created the rugments fork for the purpose of improving
gitlab's highlighting. Nowadays IMO it works way better than the old
highlight.js solution. But the development is stuck on my side because
of a couple of personal reasons:

  * I have finished my studies; last months I was writing my master
    thesis. So there was a huge time problem. I am sorry for that.

  * I had to move to Munich due to getting a (paid) job. Searching a
    flat here is horrible... :)

  * Last but not least, maintaining the same code base in two seperate
    projects is a mess.

I have decided to switch back to rouge due to several reasons:

  * In the beginning I was quite motivated, but since I start
    working on my new job next week, the best solution IMO is
    switching back to upstream rouge.

  * Rouge is continously improving:
    https://github.com/jneen/rouge/blob/master/CHANGELOG.md
    http://rouge.jneen.net/

  * There should be absolutely no regressions with this change. Most
    likely this pull request will almost fix some minor bugs.

  * One less gem in gitlab is a good thing. since Gitlab is quite a
    huge bundle of gems. Reducing complexity should be a major
    milestone.

Thanks a lot to @stanhu and @jneen for the review!
parent 5bdcef7b
...@@ -272,4 +272,3 @@ end ...@@ -272,4 +272,3 @@ end
gem "newrelic_rpm" gem "newrelic_rpm"
gem 'octokit', '3.7.0' gem 'octokit', '3.7.0'
gem "rugments", "~> 1.0.0.beta8"
...@@ -579,7 +579,6 @@ GEM ...@@ -579,7 +579,6 @@ GEM
rubyntlm (0.5.0) rubyntlm (0.5.0)
rubypants (0.2.0) rubypants (0.2.0)
rugged (0.22.2) rugged (0.22.2)
rugments (1.0.0.beta8)
safe_yaml (1.0.4) safe_yaml (1.0.4)
sanitize (2.1.0) sanitize (2.1.0)
nokogiri (>= 1.4.4) nokogiri (>= 1.4.4)
...@@ -836,7 +835,6 @@ DEPENDENCIES ...@@ -836,7 +835,6 @@ DEPENDENCIES
rqrcode-rails3 rqrcode-rails3
rspec-rails (~> 3.3.0) rspec-rails (~> 3.3.0)
rubocop (= 0.28.0) rubocop (= 0.28.0)
rugments (~> 1.0.0.beta8)
sanitize (~> 2.0) sanitize (~> 2.0)
sass-rails (~> 4.0.5) sass-rails (~> 4.0.5)
sdoc sdoc
......
module BlobHelper module BlobHelper
def highlight(blob_name, blob_content, nowrap: false, continue: false) def highlight(blob_name, blob_content, nowrap: false, continue: false)
@formatter ||= Rugments::Formatters::HTML.new( @formatter ||= Rouge::Formatters::HTMLGitlab.new(
nowrap: nowrap, nowrap: nowrap,
cssclass: 'code highlight', cssclass: 'code highlight',
lineanchors: true, lineanchors: true,
...@@ -8,11 +8,11 @@ module BlobHelper ...@@ -8,11 +8,11 @@ module BlobHelper
) )
begin begin
@lexer ||= Rugments::Lexer.guess(filename: blob_name, source: blob_content).new @lexer ||= Rouge::Lexer.guess(filename: blob_name, source: blob_content)
result = @formatter.format(@lexer.lex(blob_content, continue: continue)).html_safe result = @formatter.format(@lexer.lex(blob_content, continue: continue)).html_safe
rescue rescue
lexer = Rugments::Lexers::PlainText @lexer = Rouge::Lexers::PlainText
result = @formatter.format(lexer.lex(blob_content)).html_safe result = @formatter.format(@lexer.lex(blob_content)).html_safe
end end
result result
......
...@@ -31,8 +31,8 @@ module EmailsHelper ...@@ -31,8 +31,8 @@ module EmailsHelper
end end
def color_email_diff(diffcontent) def color_email_diff(diffcontent)
formatter = Rugments::Formatters::HTML.new(cssclass: "highlight", inline_theme: :github) formatter = Rouge::Formatters::HTML.new(css_class: 'highlight', inline_theme: 'github')
lexer = Rugments::Lexers::Diff.new lexer = Rouge::Lexers::Diff
raw formatter.format(lexer.lex(diffcontent)) raw formatter.format(lexer.lex(diffcontent))
end end
......
...@@ -22,10 +22,10 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML ...@@ -22,10 +22,10 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
ERB::Util.html_escape_once(text) ERB::Util.html_escape_once(text)
end end
# Stolen from Rugments::Plugins::Redcarpet as this module is not required # Stolen from Rouge::Plugins::Redcarpet as this module is not required
# from Rugments's gem root. # from Rouge's gem root.
def block_code(code, language) def block_code(code, language)
lexer = Rugments::Lexer.find_fancy(language, code) || Rugments::Lexers::PlainText lexer = Rouge::Lexer.find_fancy(language, code) || Rouge::Lexers::PlainText
# XXX HACK: Redcarpet strips hard tabs out of code blocks, # XXX HACK: Redcarpet strips hard tabs out of code blocks,
# so we assume you're not using leading spaces that aren't tabs, # so we assume you're not using leading spaces that aren't tabs,
...@@ -34,7 +34,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML ...@@ -34,7 +34,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
code.gsub!(/^ /, "\t") code.gsub!(/^ /, "\t")
end end
formatter = Rugments::Formatters::HTML.new( formatter = Rouge::Formatters::HTMLGitlab.new(
cssclass: "code highlight #{@color_scheme} #{lexer.tag}" cssclass: "code highlight #{@color_scheme} #{lexer.tag}"
) )
formatter.format(lexer.lex(code)) formatter.format(lexer.lex(code))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment