summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2015-09-09 18:37:45 +0000
committerRobert Speicher <robert@gitlab.com>2015-09-09 18:37:45 +0000
commita81ce718c772672706da33848670149dd577ae79 (patch)
tree44a56d1dee93c0eef3a9e93c6a14bf9de4f9c442
parent3b610d98213716ae01ba9dcbc1bd76eecfaf3738 (diff)
parentd3730b071365dd3dbfa0b8ec4433e1f18a93c969 (diff)
downloadgitlab-ce-a81ce718c772672706da33848670149dd577ae79.tar.gz
Merge branch 'rouge-patch' into 'master'
Fix highlighting of deleted lines in diffs. Resolves internal https://dev.gitlab.org/gitlab/gitlabhq/issues/2498 Only needed until https://github.com/jneen/rouge/pull/297 is merged into Rouge and the gem is updated in GitLab. Forking `rouge`, releasing `gitlab-rouge` and using that gem wasn't an option, since `gollum-lib` has `rouge` as a dependency, so it would get included anyway, and which code we'd get would depend on the load order. See merge request !1267
-rw-r--r--CHANGELOG1
-rw-r--r--config/initializers/rouge_diff_lexer.rb24
2 files changed, 25 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index c50ea05b8f6..36ee3e69ab3 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -42,6 +42,7 @@ v 8.0.0 (unreleased)
- Fix bug which IE cannot show image at markdown when the image is raw file of gitlab
- Add support for Crowd
- Global Labels that are available to all projects
+ - Fix highlighting of deleted lines in diffs.
v 7.14.1
- Improve abuse reports management from admin area
diff --git a/config/initializers/rouge_diff_lexer.rb b/config/initializers/rouge_diff_lexer.rb
new file mode 100644
index 00000000000..fdb2d7b748e
--- /dev/null
+++ b/config/initializers/rouge_diff_lexer.rb
@@ -0,0 +1,24 @@
+# Here until https://github.com/jneen/rouge/pull/297 is merged into Rouge and the gem is updated in GitLab.
+module Rouge
+ module Lexers
+ class Diff
+ def self.analyze_text(text)
+ return 1 if text.start_with?('Index: ')
+ return 1 if text.start_with?('diff ')
+ return 0.9 if text.start_with?('--- ')
+ end
+
+ state :root do
+ rule(/^ .*\n/, Text)
+ rule(/^---\n/, Text)
+ rule(/^\+.*\n/, Generic::Inserted)
+ rule(/^-+.*\n/, Generic::Deleted)
+ rule(/^!.*\n/, Generic::Strong)
+ rule(/^@.*\n/, Generic::Subheading)
+ rule(/^([Ii]ndex|diff).*\n/, Generic::Heading)
+ rule(/^=.*\n/, Generic::Heading)
+ rule(/.*\n/, Text)
+ end
+ end
+ end
+end