From 891ea6f6e66c753d9a2f7a4e261f4d37e118c253 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 27 Jan 2014 18:18:18 +0200 Subject: [PATCH] Improve highlight for notes Signed-off-by: Dmitriy Zaporozhets --- app/assets/javascripts/dispatcher.js.coffee | 2 +- app/assets/javascripts/notes.js.coffee | 6 ++++++ app/assets/stylesheets/generic/highlight.scss | 5 +---- app/assets/stylesheets/main/mixins.scss | 2 +- app/assets/stylesheets/sections/notes.scss | 4 ---- lib/redcarpet/render/gitlab_html.rb | 4 +--- spec/helpers/gitlab_markdown_helper_spec.rb | 2 +- 7 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee index 3ae6d32210e..9afb5974858 100644 --- a/app/assets/javascripts/dispatcher.js.coffee +++ b/app/assets/javascripts/dispatcher.js.coffee @@ -56,7 +56,7 @@ class Dispatcher new SearchAutocomplete(path, project_id, project_ref) initHighlight: -> - $('pre code').each (i, e) -> + $('.highlight pre code').each (i, e) -> hljs.highlightBlock(e) $(e).html($.map($(e).html().split("\n"), (line, i) -> "
" + line + "
" diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee index 69e9e67f712..d200d962cae 100644 --- a/app/assets/javascripts/notes.js.coffee +++ b/app/assets/javascripts/notes.js.coffee @@ -94,6 +94,9 @@ class Notes if @isNewNote(note) @note_ids.push(note.id) $('ul.main-notes-list').append(note.html) + code = "#note_" + note.id + " .highlight pre code" + $(code).each (i, e) -> + hljs.highlightBlock(e) ### @@ -253,6 +256,9 @@ class Notes updateNote: (xhr, note, status) => note_li = $("#note_" + note.id) note_li.replaceWith(note.html) + code = "#note_" + note.id + " .highlight pre code" + $(code).each (i, e) -> + hljs.highlightBlock(e) ### Called in response to clicking the edit note link diff --git a/app/assets/stylesheets/generic/highlight.scss b/app/assets/stylesheets/generic/highlight.scss index 7614d2083fc..f8316caca97 100644 --- a/app/assets/stylesheets/generic/highlight.scss +++ b/app/assets/stylesheets/generic/highlight.scss @@ -6,6 +6,7 @@ table-layout: fixed; pre { + padding: 10px; border: none; border-radius: 0; font-family: $monospace_font; @@ -57,10 +58,6 @@ pre { white-space: pre; word-wrap: normal; - - .line { - padding: 0 10px; - } } } } diff --git a/app/assets/stylesheets/main/mixins.scss b/app/assets/stylesheets/main/mixins.scss index e637b645b55..0e76808d3e8 100644 --- a/app/assets/stylesheets/main/mixins.scss +++ b/app/assets/stylesheets/main/mixins.scss @@ -128,7 +128,7 @@ } } - code { + p > code { font-size: inherit; font-weight: inherit; color: #555; diff --git a/app/assets/stylesheets/sections/notes.scss b/app/assets/stylesheets/sections/notes.scss index 1ae0e161aa2..be62341ed65 100644 --- a/app/assets/stylesheets/sections/notes.scss +++ b/app/assets/stylesheets/sections/notes.scss @@ -92,10 +92,6 @@ ul.notes { .note-body { @include md-typography; margin-left: 45px; - - .highlight { - @include border-radius(4px); - } } .note-header { padding-bottom: 5px; diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb index b3e8ed2ade5..6da0c1d6f96 100644 --- a/lib/redcarpet/render/gitlab_html.rb +++ b/lib/redcarpet/render/gitlab_html.rb @@ -23,9 +23,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
-
-      #{code}
-    
+
#{code}
diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index daceb214be7..427ac0f8083 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -378,7 +378,7 @@ describe GitlabMarkdownHelper do it "should leave code blocks untouched" do helper.stub(:user_color_scheme_class).and_return(:white) - target_html = "\n
\n
\n
\n      some code from $#{snippet.id}\nhere too\n\n    
\n
\n
\n\n" + target_html = "\n
\n
\n
some code from $#{snippet.id}\nhere too\n
\n
\n
\n\n" helper.markdown("\n some code from $#{snippet.id}\n here too\n").should == target_html helper.markdown("\n```\nsome code from $#{snippet.id}\nhere too\n```\n").should == target_html -- GitLab