summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-02-27 17:17:57 -0800
committerStan Hu <stanhu@gmail.com>2015-03-10 08:11:20 -0700
commit4218a2bfcf7a3f864268c3eafe8ead28bb7808d8 (patch)
treed3860750b344916b1461386ac68990d8d42f439c
parent332413d7c4003c3718f8d91c54d7f3410710a5f9 (diff)
downloadgitlab-ce-4218a2bfcf7a3f864268c3eafe8ead28bb7808d8.tar.gz
Fix code preview theme setting for comments, issues, merge requests, and snippets.
Also preserve code preview color scheme in events dashboard. Assign default colors to all code blocks shown as <pre class="code highlight [color_scheme]"> Closes #1139
-rw-r--r--CHANGELOG1
-rw-r--r--app/assets/stylesheets/highlight/dark.scss4
-rw-r--r--app/assets/stylesheets/highlight/monokai.scss4
-rw-r--r--app/assets/stylesheets/highlight/solarized_dark.scss4
-rw-r--r--app/assets/stylesheets/highlight/solarized_light.scss4
-rw-r--r--app/assets/stylesheets/highlight/white.scss4
-rw-r--r--app/helpers/events_helper.rb2
-rw-r--r--app/helpers/gitlab_markdown_helper.rb4
-rw-r--r--lib/redcarpet/render/gitlab_html.rb5
-rw-r--r--spec/helpers/events_helper_spec.rb12
10 files changed, 40 insertions, 4 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 81468d4013e..0ffdbc8391d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,7 @@ v 7.9.0 (unreleased)
- Add issue and merge request events to HipChat and Slack services (Stan Hu)
- Fix merge request URL passed to Webhooks. (Stan Hu)
- Fix bug that caused a server error when editing a comment to "+1" or "-1" (Stan Hu)
+ - Fix code preview theme setting for comments, issues, merge requests, and snippets (Stan Hu)
- Move labels/milestones tabs to sidebar
- Upgrade Rails gem to version 4.1.9.
- Improve error messages for file edit failures
diff --git a/app/assets/stylesheets/highlight/dark.scss b/app/assets/stylesheets/highlight/dark.scss
index fcd4d47bace..01e12323c7e 100644
--- a/app/assets/stylesheets/highlight/dark.scss
+++ b/app/assets/stylesheets/highlight/dark.scss
@@ -1,6 +1,10 @@
/* https://github.com/MozMorris/tomorrow-pygments */
+pre.code.highlight.dark,
.code.dark {
+ background-color: #1d1f21;
+ color: #c5c8c6;
+
pre.code,
.line-numbers,
.line-numbers a {
diff --git a/app/assets/stylesheets/highlight/monokai.scss b/app/assets/stylesheets/highlight/monokai.scss
index bcd2e716657..e7d62a7ca1a 100644
--- a/app/assets/stylesheets/highlight/monokai.scss
+++ b/app/assets/stylesheets/highlight/monokai.scss
@@ -1,6 +1,10 @@
/* https://github.com/richleland/pygments-css/blob/master/monokai.css */
+pre.code.monokai,
.code.monokai {
+ background: #272822;
+ color: #f8f8f2;
+
pre.highlight,
.line-numbers,
.line-numbers a {
diff --git a/app/assets/stylesheets/highlight/solarized_dark.scss b/app/assets/stylesheets/highlight/solarized_dark.scss
index 4a6b759bd2c..de2676e39cf 100644
--- a/app/assets/stylesheets/highlight/solarized_dark.scss
+++ b/app/assets/stylesheets/highlight/solarized_dark.scss
@@ -1,6 +1,10 @@
/* https://gist.github.com/qguv/7936275 */
+pre.code.highlight.solarized-dark,
.code.solarized-dark {
+ background-color: #002b36;
+ color: #93a1a1;
+
pre.code,
.line-numbers,
.line-numbers a {
diff --git a/app/assets/stylesheets/highlight/solarized_light.scss b/app/assets/stylesheets/highlight/solarized_light.scss
index 7254f4d7ac1..784e768914c 100644
--- a/app/assets/stylesheets/highlight/solarized_light.scss
+++ b/app/assets/stylesheets/highlight/solarized_light.scss
@@ -1,6 +1,10 @@
/* https://gist.github.com/qguv/7936275 */
+pre.code.highlight.solarized-light,
.code.solarized-light {
+ background-color: #fdf6e3;
+ color: #586e75;
+
pre.code,
.line-numbers,
.line-numbers a {
diff --git a/app/assets/stylesheets/highlight/white.scss b/app/assets/stylesheets/highlight/white.scss
index 4d6f5dfd91e..9b9b0a6bd6d 100644
--- a/app/assets/stylesheets/highlight/white.scss
+++ b/app/assets/stylesheets/highlight/white.scss
@@ -1,6 +1,10 @@
/* https://github.com/aahan/pygments-github-style */
+pre.code.highlight.white,
.code.white {
+ background-color: #fff;
+ color: #333;
+
pre.highlight,
.line-numbers,
.line-numbers a {
diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb
index d38b546e1b2..779cebc0136 100644
--- a/app/helpers/events_helper.rb
+++ b/app/helpers/events_helper.rb
@@ -166,7 +166,7 @@ module EventsHelper
def event_note(text)
text = first_line_in_markdown(text, 150)
- sanitize(text, tags: %w(a img b pre code p))
+ sanitize(text, tags: %w(a img b pre code p span))
end
def event_commit_title(message)
diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb
index ab30f498c01..daaefe90f18 100644
--- a/app/helpers/gitlab_markdown_helper.rb
+++ b/app/helpers/gitlab_markdown_helper.rb
@@ -31,7 +31,9 @@ module GitlabMarkdownHelper
def markdown(text, options={})
unless (@markdown and options == @options)
@options = options
- gitlab_renderer = Redcarpet::Render::GitlabHTML.new(self, {
+ gitlab_renderer = Redcarpet::Render::GitlabHTML.new(self,
+ user_color_scheme_class,
+ {
# see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch-
filter_html: true,
with_toc_data: true,
diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb
index 714261f815c..713d7c39a11 100644
--- a/lib/redcarpet/render/gitlab_html.rb
+++ b/lib/redcarpet/render/gitlab_html.rb
@@ -3,8 +3,9 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
attr_reader :template
alias_method :h, :template
- def initialize(template, options = {})
+ def initialize(template, color_scheme, options = {})
@template = template
+ @color_scheme = color_scheme
@project = @template.instance_variable_get("@project")
@options = options.dup
super options
@@ -34,7 +35,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
end
formatter = Rugments::Formatters::HTML.new(
- cssclass: "code highlight white #{lexer.tag}"
+ cssclass: "code highlight #{@color_scheme} #{lexer.tag}"
)
formatter.format(lexer.lex(code))
end
diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb
index c4a192ac1aa..b392371deb4 100644
--- a/spec/helpers/events_helper_spec.rb
+++ b/spec/helpers/events_helper_spec.rb
@@ -4,6 +4,8 @@ describe EventsHelper do
include ApplicationHelper
include GitlabMarkdownHelper
+ let(:current_user) { create(:user, email: "current@email.com") }
+
it 'should display one line of plain text without alteration' do
input = 'A short, plain note'
expect(event_note(input)).to match(input)
@@ -50,4 +52,14 @@ describe EventsHelper do
expect(event_note(input)).to match(link_url)
expect(event_note(input)).to match(expected_link_text)
end
+
+ it 'should preserve code color scheme' do
+ input = "```ruby\ndef test\n 'hello world'\nend\n```"
+ expected = '<pre class="code highlight white ruby">' \
+ "<code><span class=\"k\">def</span> <span class=\"nf\">test</span>\n" \
+ " <span class=\"s1\">\'hello world\'</span>\n" \
+ "<span class=\"k\">end</span>\n" \
+ '</code></pre>'
+ expect(event_note(input)).to eq(expected)
+ end
end