Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G gitlabhq1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gpt
  • large_projects
  • gitlabhq1
  • Issues
  • #6994

Closed
Open
Created May 18, 2014 by Administrator@rootOwner

Syntax highlighting diff in repository_push_email.html.haml

Created by: grgcombs

Trying to determine the best way of enabling 'diff' syntax highlighting for the repository_push_email.html.haml commit diffs. I initially tried to use the highlight.js javascript library but I think many email clients don't/won't process javascript embedded in the html body of an email message. The ones I tried completely ignored the javascript.

So, my next thought was to try using the Rouge gem, since it doesn't require Python processes like other gems based on Pygments. Is there any interest in including support for colorized diffs?

Assuming you've run gem install rouge before this...

app/views/layouts/notify.html.haml

diff --git a/app/views/layouts/notify.html.haml b/app/views/layouts/notify.html.
index 991d4f0..cba9595 100644
--- a/app/views/layouts/notify.html.haml
+++ b/app/views/layouts/notify.html.haml
@@ -3,15 +3,15 @@
     %meta{content: "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
       %title
         GitLab
-  :css
-    p.details {
-      font-style:italic;
-      color:#777
-    }
-    .footer p {
-      font-size:small;
-      color:#777
-    }
+  :ruby
+    require 'rouge'
+    stock_style = 'p.details { font-style:italic; color:#777 }'
+    stock_style2 = '.footer p { font-size:small; color:#777 }'
+    haml_io.puts '<style>'
+    haml_io.puts stock_style
+    haml_io.puts stock_style2
+    haml_io.puts Rouge::Themes::Github.render(:scope => '.highlight')
+    haml_io.puts '</style>'
   %body
     %div.content

app/views/notify/repository_push_email.html.haml

diff --git a/app/views/notify/repository_push_email.html.haml b/app/views/notify
index 85a01a5..b4119af 100644
--- a/app/views/notify/repository_push_email.html.haml
+++ b/app/views/notify/repository_push_email.html.haml
@@ -17,10 +17,14 @@
         #{diff.old_path} &rarr; #{diff.new_path}
       - else
         = diff.new_path || diff.old_path
-    %hr
-    %pre
-      = diff.diff
-    %br
+  %hr
+  :ruby
+    require 'rouge'
+    lexer = Rouge::Lexers::Diff.new
+    formatter = Rouge::Formatters::HTML.new(:css_class => 'highlight')
+    lexer = Rouge::Lexers::Diff.new
+    haml_io.puts formatter.format(lexer.lex(diff.diff))
+  %br

 - if @compare.timeout
   %h5 To prevent performance issues changes are hidden
Assignee
Assign to
Time tracking