From 65af1e443620747e758e1ad4699a0c524b456db8 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sat, 29 Oct 2011 11:35:16 +0200 Subject: [PATCH 1/6] #649 update to CodeRay 1.0 according to Etienne's r7618 in Redmine --- Gemfile | 2 +- app/views/help/wiki_syntax_detailed.html.erb | 45 ++--- lib/redmine/syntax_highlighting.rb | 2 +- public/stylesheets/scm.css | 176 +++++++++---------- test/fixtures/diffs/subversion.diff | 2 +- test/unit/helpers/application_helper_test.rb | 2 +- 6 files changed, 108 insertions(+), 121 deletions(-) diff --git a/Gemfile b/Gemfile index 7b02dfa5..5ea991b1 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source :rubygems gem "rails", "2.3.12" -gem "coderay", "~> 0.9.7" +gem "coderay", "~> 1.0.0" gem "i18n", "~> 0.4.2" gem "rubytree", "~> 0.5.2", :require => 'tree' gem "rdoc", ">= 2.4.2" diff --git a/app/views/help/wiki_syntax_detailed.html.erb b/app/views/help/wiki_syntax_detailed.html.erb index 26603f5f..fa1e9ae9 100644 --- a/app/views/help/wiki_syntax_detailed.html.erb +++ b/app/views/help/wiki_syntax_detailed.html.erb @@ -13,20 +13,22 @@ } a.new { color: #b73535; } - .CodeRay .c { color:#666; } + .syntaxhl .line-numbers { padding: 2px 4px 2px 4px; background-color: #eee; margin:0 } + .syntaxhl .comment { color:#666; } - .CodeRay .cl { color:#B06; font-weight:bold } - .CodeRay .dl { color:black } - .CodeRay .fu { color:#06B; font-weight:bold } + .syntaxhl .class { color:#B06; font-weight:bold } + .syntaxhl .delimiter { color:black } + .syntaxhl .function { color:#06B; font-weight:bold } - .CodeRay .il { background: #eee } - .CodeRay .il .idl { font-weight: bold; color: #888 } + .syntaxhl .inline { background: #eee } + .syntaxhl .inline .inline-delimiter { font-weight: bold; color: #888 } - .CodeRay .iv { color:#33B } - .CodeRay .r { color:#080; font-weight:bold } + .syntaxhl .instance-variable { color:#33B } + .syntaxhl .reserved { color:#080; font-weight:bold } + + .syntaxhl .string { background-color:#fff0f0; color: #D20; } + .syntaxhl .string .delimiter { color:#710 } - .CodeRay .s { background-color:#fff0f0 } - .CodeRay .s .dl { color:#710 } <% end %> <% html_title "Wiki Formatting" %> @@ -236,7 +238,7 @@ To go live, all you need to add is a database and a web server.

Code highlighting

-

Code highlightment relies on CodeRay, a fast syntax highlighting library written completely in Ruby. It currently supports c, cpp, css, delphi, groovy, html, java, javascript, json, php, python, rhtml, ruby, scheme, sql, xml and yaml languages.

+

Default code highlightment relies on CodeRay, a fast syntax highlighting library written completely in Ruby. It currently supports c, cpp, css, delphi, groovy, html, java, javascript, json, php, python, rhtml, ruby, scheme, sql, xml and yaml languages.

You can highlight code in your wiki page using this syntax:

@@ -248,15 +250,14 @@ To go live, all you need to add is a database and a web server.

Example:

-
 1 # The Greeter class
- 2 class Greeter
- 3   def initialize(name)
- 4     @name = name.capitalize
- 5   end
- 6
- 7   def salute
- 8     puts "Hello #{@name}!"
- 9   end
-10 end
-
+
 1 # The Greeter class
+ 2 class Greeter
+ 3   def initialize(name)
+ 4     @name = name.capitalize
+ 5   end
+ 6 
+ 7   def salute
+ 8     puts "Hello #{@name}!" 
+ 9   end
+10 end
 
diff --git a/lib/redmine/syntax_highlighting.rb b/lib/redmine/syntax_highlighting.rb index ff16b967..9f06f8f7 100644 --- a/lib/redmine/syntax_highlighting.rb +++ b/lib/redmine/syntax_highlighting.rb @@ -42,7 +42,7 @@ module Redmine # Highlights +text+ using +language+ syntax # Should not return outer pre tag def highlight_by_language(text, language) - ::CodeRay.scan(text, language).html(:line_numbers => :inline, :wrap => :span) + ::CodeRay.scan(text, language).html(:line_numbers => :inline, :line_number_anchors => false, :wrap => :span) end end end diff --git a/public/stylesheets/scm.css b/public/stylesheets/scm.css index b974e2b3..03ad3975 100644 --- a/public/stylesheets/scm.css +++ b/public/stylesheets/scm.css @@ -95,101 +95,87 @@ div.action_A { background: #bfb } .syntaxhl .code pre { overflow: auto } .syntaxhl .debug { color:white ! important; background:blue ! important; } -.syntaxhl .af { color:#00C } -.syntaxhl .an { color:#007 } -.syntaxhl .at { color:#f08 } -.syntaxhl .av { color:#700 } -.syntaxhl .aw { color:#C00 } -.syntaxhl .bi { color:#509; font-weight:bold } -.syntaxhl .c { color:#888; } +.syntaxhl .annotation { color:#007 } +.syntaxhl .attribute-name { color:#b48 } +.syntaxhl .attribute-value { color:#700 } +.syntaxhl .binary { color:#509 } +.syntaxhl .char .content { color:#D20 } +.syntaxhl .char .delimiter { color:#710 } +.syntaxhl .char { color:#D20 } +.syntaxhl .class { color:#B06; font-weight:bold } +.syntaxhl .class-variable { color:#369 } +.syntaxhl .color { color:#0A0 } +.syntaxhl .comment { color:#777 } +.syntaxhl .comment .char { color:#444 } +.syntaxhl .comment .delimiter { color:#444 } +.syntaxhl .complex { color:#A08 } +.syntaxhl .constant { color:#036; font-weight:bold } +.syntaxhl .decorator { color:#B0B } +.syntaxhl .definition { color:#099; font-weight:bold } +.syntaxhl .delimiter { color:black } +.syntaxhl .directive { color:#088; font-weight:bold } +.syntaxhl .doc { color:#970 } +.syntaxhl .doc-string { color:#D42; font-weight:bold } +.syntaxhl .doctype { color:#34b } +.syntaxhl .entity { color:#800; font-weight:bold } +.syntaxhl .error { color:#F00; background-color:#FAA } +.syntaxhl .escape { color:#666 } +.syntaxhl .exception { color:#C00; font-weight:bold } +.syntaxhl .float { color:#60E } +.syntaxhl .function { color:#06B; font-weight:bold } +.syntaxhl .global-variable { color:#d70 } +.syntaxhl .hex { color:#02b } +.syntaxhl .imaginary { color:#f00 } +.syntaxhl .include { color:#B44; font-weight:bold } +.syntaxhl .inline { background-color: hsla(0,0%,0%,0.07); color: black } +.syntaxhl .inline-delimiter { font-weight: bold; color: #666 } +.syntaxhl .instance-variable { color:#33B } +.syntaxhl .integer { color:#00D } +.syntaxhl .key .char { color: #60f } +.syntaxhl .key .delimiter { color: #404 } +.syntaxhl .key { color: #606 } +.syntaxhl .keyword { color:#080; font-weight:bold } +.syntaxhl .label { color:#970; font-weight:bold } +.syntaxhl .local-variable { color:#963 } +.syntaxhl .namespace { color:#707; font-weight:bold } +.syntaxhl .octal { color:#40E } +.syntaxhl .operator { } +.syntaxhl .predefined { color:#369; font-weight:bold } +.syntaxhl .predefined-constant { color:#069 } +.syntaxhl .predefined-type { color:#0a5; font-weight:bold } +.syntaxhl .preprocessor { color:#579 } +.syntaxhl .pseudo-class { color:#00C; font-weight:bold } +.syntaxhl .regexp .content { color:#808 } +.syntaxhl .regexp .delimiter { color:#404 } +.syntaxhl .regexp .modifier { color:#C2C } +.syntaxhl .regexp { background-color:hsla(300,100%,50%,0.06); } +.syntaxhl .reserved { color:#080; font-weight:bold } +.syntaxhl .shell .content { color:#2B2 } +.syntaxhl .shell .delimiter { color:#161 } +.syntaxhl .shell { background-color:hsla(120,100%,50%,0.06); } +.syntaxhl .string .char { color: #b0b } +.syntaxhl .string .content { color: #D20 } +.syntaxhl .string .delimiter { color: #710 } +.syntaxhl .string .modifier { color: #E40 } +.syntaxhl .string { background-color:hsla(0,100%,50%,0.05); } +.syntaxhl .symbol .content { color:#A60 } +.syntaxhl .symbol .delimiter { color:#630 } +.syntaxhl .symbol { color:#A60 } +.syntaxhl .tag { color:#070 } +.syntaxhl .type { color:#339; font-weight:bold } +.syntaxhl .value { color: #088; } +.syntaxhl .variable { color:#037 } -.syntaxhl .ch { color:#04D } -.syntaxhl .ch .k { color:#04D } -.syntaxhl .ch .dl { color:#039 } - -.syntaxhl .cl { color:#B06; font-weight:bold } -.syntaxhl .cm { color:#A08; font-weight:bold } -.syntaxhl .co { color:#036; font-weight:bold } -.syntaxhl .cr { color:#0A0 } -.syntaxhl .cv { color:#369 } -.syntaxhl .de { color:#B0B; } -.syntaxhl .df { color:#099; font-weight:bold } -.syntaxhl .di { color:#088; font-weight:bold } -.syntaxhl .dl { color:black } -.syntaxhl .do { color:#970 } -.syntaxhl .dt { color:#34b } -.syntaxhl .ds { color:#D42; font-weight:bold } -.syntaxhl .e { color:#666; font-weight:bold } -.syntaxhl .en { color:#800; font-weight:bold } -.syntaxhl .er { color:#F00; background-color:#FAA } -.syntaxhl .ex { color:#C00; font-weight:bold } -.syntaxhl .fl { color:#60E; font-weight:bold } -.syntaxhl .fu { color:#06B; font-weight:bold } -.syntaxhl .gv { color:#d70; font-weight:bold } -.syntaxhl .hx { color:#058; font-weight:bold } -.syntaxhl .i { color:#00D; font-weight:bold } -.syntaxhl .ic { color:#B44; font-weight:bold } - -.syntaxhl .il { background: #ddd; color: black } -.syntaxhl .il .il { background: #ccc } -.syntaxhl .il .il .il { background: #bbb } -.syntaxhl .il .idl { background: #ddd; font-weight: bold; color: #666 } -.syntaxhl .idl { background-color: #bbb; font-weight: bold; color: #666; } - -.syntaxhl .im { color:#f00; } -.syntaxhl .in { color:#B2B; font-weight:bold } -.syntaxhl .iv { color:#33B } -.syntaxhl .la { color:#970; font-weight:bold } -.syntaxhl .lv { color:#963 } -.syntaxhl .oc { color:#40E; font-weight:bold } -.syntaxhl .of { color:#000; font-weight:bold } -.syntaxhl .op { } -.syntaxhl .pc { color:#038; font-weight:bold } -.syntaxhl .pd { color:#369; font-weight:bold } -.syntaxhl .pp { color:#579; } -.syntaxhl .ps { color:#00C; font-weight:bold } -.syntaxhl .pt { color:#074; font-weight:bold } -.syntaxhl .r, .kw { color:#080; font-weight:bold } - -.syntaxhl .ke { color: #808; } -.syntaxhl .ke .dl { color: #606; } -.syntaxhl .ke .ch { color: #80f; } -.syntaxhl .vl { color: #088; } - -.syntaxhl .rx { background-color:#fff0ff } -.syntaxhl .rx .k { color:#808 } -.syntaxhl .rx .dl { color:#404 } -.syntaxhl .rx .mod { color:#C2C } -.syntaxhl .rx .fu { color:#404; font-weight: bold } - -.syntaxhl .s { background-color:#fff0f0; color: #D20; } -.syntaxhl .s .s { background-color:#ffe0e0 } -.syntaxhl .s .s .s { background-color:#ffd0d0 } -.syntaxhl .s .k { } -.syntaxhl .s .ch { color: #b0b; } -.syntaxhl .s .dl { color: #710; } - -.syntaxhl .sh { background-color:#f0fff0; color:#2B2 } -.syntaxhl .sh .k { } -.syntaxhl .sh .dl { color:#161 } - -.syntaxhl .sy { color:#A60 } -.syntaxhl .sy .k { color:#A60 } -.syntaxhl .sy .dl { color:#630 } - -.syntaxhl .ta { color:#070 } -.syntaxhl .tf { color:#070; font-weight:bold } -.syntaxhl .ts { color:#D70; font-weight:bold } -.syntaxhl .ty { color:#339; font-weight:bold } -.syntaxhl .v { color:#036 } -.syntaxhl .xt { color:#444 } - -.syntaxhl .ins { background: #cfc; } -.syntaxhl .del { background: #fcc; } -.syntaxhl .chg { color: #aaf; background: #007; } +.syntaxhl .insert { background: hsla(120,100%,50%,0.12) } +.syntaxhl .delete { background: hsla(0,100%,50%,0.12) } +.syntaxhl .change { color: #bbf; background: #007; } .syntaxhl .head { color: #f8f; background: #505 } +.syntaxhl .head .filename { color: white; } -.syntaxhl .ins .ins { color: #080; font-weight:bold } -.syntaxhl .del .del { color: #800; font-weight:bold } -.syntaxhl .chg .chg { color: #66f; } -.syntaxhl .head .head { color: #f4f; } +.syntaxhl .delete .eyecatcher { background-color: hsla(0,100%,50%,0.2); border: 1px solid hsla(0,100%,45%,0.5); margin: -1px; border-bottom: none; border-top-left-radius: 5px; border-top-right-radius: 5px; } +.syntaxhl .insert .eyecatcher { background-color: hsla(120,100%,50%,0.2); border: 1px solid hsla(120,100%,25%,0.5); margin: -1px; border-top: none; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; } + +.syntaxhl .insert .insert { color: #0c0; background:transparent; font-weight:bold } +.syntaxhl .delete .delete { color: #c00; background:transparent; font-weight:bold } +.syntaxhl .change .change { color: #88f } +.syntaxhl .head .head { color: #f4f } diff --git a/test/fixtures/diffs/subversion.diff b/test/fixtures/diffs/subversion.diff index 9b6c9d08..67def6bf 100644 --- a/test/fixtures/diffs/subversion.diff +++ b/test/fixtures/diffs/subversion.diff @@ -22,7 +22,7 @@ Index: app/views/common/_diff.rhtml +<% diff.each do |table_file| -%>
<% if diff_type == 'sbs' -%> - +
@@ -62,3 +63,5 @@ diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 10ba5126..b12a9b5e 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -474,7 +474,7 @@ EXPECTED RAW expected = <<-EXPECTED -
1 # Some ruby code here
+
1 # Some ruby code here
 
EXPECTED From 7b1a263d1db75687541589f3427eac51c8598534 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sat, 29 Oct 2011 12:10:18 +0200 Subject: [PATCH 2/6] trying to fix wiki syntaxhl issue --- public/stylesheets/scm.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/stylesheets/scm.css b/public/stylesheets/scm.css index 03ad3975..9f9b96a2 100644 --- a/public/stylesheets/scm.css +++ b/public/stylesheets/scm.css @@ -91,7 +91,7 @@ div.action_A { background: #bfb } /************* CodeRay styles *************/ .syntaxhl div {display: inline;} -.syntaxhl .no { padding: 2px 4px 2px 4px; background-color: #eee; margin:0 } +.syntaxhl .line-numbers { padding: 2px 4px 2px 4px; background-color: #eee; margin:0; margin-right: 4px } .syntaxhl .code pre { overflow: auto } .syntaxhl .debug { color:white ! important; background:blue ! important; } From 260a6bb1da942493bb26f80e29079384e0020a91 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sat, 29 Oct 2011 12:20:11 +0200 Subject: [PATCH 3/6] fixed wiki syntaxhl issue --- public/stylesheets/scm.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/stylesheets/scm.css b/public/stylesheets/scm.css index 9f9b96a2..2b1fed44 100644 --- a/public/stylesheets/scm.css +++ b/public/stylesheets/scm.css @@ -91,7 +91,7 @@ div.action_A { background: #bfb } /************* CodeRay styles *************/ .syntaxhl div {display: inline;} -.syntaxhl .line-numbers { padding: 2px 4px 2px 4px; background-color: #eee; margin:0; margin-right: 4px } +.syntaxhl .line-numbers { padding: 2px 4px 2px 4px; background-color: #eee; margin: 0 7px 0 0; } .syntaxhl .code pre { overflow: auto } .syntaxhl .debug { color:white ! important; background:blue ! important; } From aa8237c546f6d47c814bdb02b633340d576b22b2 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sat, 29 Oct 2011 13:44:47 +0200 Subject: [PATCH 4/6] fix application_helper_test --- test/unit/helpers/application_helper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index b12a9b5e..e9919980 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -474,7 +474,7 @@ EXPECTED RAW expected = <<-EXPECTED -
1 # Some ruby code here
+
1# Some ruby code here
 
EXPECTED From 8671006b70501d82c7176a2166bbed1703ec1ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=A4fer?= Date: Fri, 9 Dec 2011 16:14:15 +0100 Subject: [PATCH 5/6] [#649] Prevent the extra wiki styles from interfering with code highlighting. --- public/stylesheets/application.css | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 19528ae4..9a4df9d1 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -2354,6 +2354,17 @@ Additional wiki styles padding: 4px 4px 4px 48px; min-height: 33px; } + +/* Reset .wiki p.important for syntax highlighting rules */ +.syntaxhl .CodeRay .important { + background: none; + border: none; + display: inline; + margin: 0; + padding: 0; + min-height: 0; +} + .wiki p.smallsee-also, .wiki p.smallcaution, .wiki p.smallimportant, .wiki p.smallinfo, .wiki p.smalltip, .wiki p.smallnote, .wiki span.smallsee-also, .wiki span.smallcaution, .wiki span.smallimportant, .wiki span.smallinfo, .wiki span.smalltip, .wiki span.smallnote { display: block; From 1c84fc0f4db9ebf599cfb1ee5e6679950116959d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=A4fer?= Date: Fri, 9 Dec 2011 16:15:40 +0100 Subject: [PATCH 6/6] Text corrections. --- app/views/help/wiki_syntax_detailed.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/help/wiki_syntax_detailed.html.erb b/app/views/help/wiki_syntax_detailed.html.erb index fa1e9ae9..50f7e00c 100644 --- a/app/views/help/wiki_syntax_detailed.html.erb +++ b/app/views/help/wiki_syntax_detailed.html.erb @@ -238,7 +238,7 @@ To go live, all you need to add is a database and a web server.

Code highlighting

-

Default code highlightment relies on CodeRay, a fast syntax highlighting library written completely in Ruby. It currently supports c, cpp, css, delphi, groovy, html, java, javascript, json, php, python, rhtml, ruby, scheme, sql, xml and yaml languages.

+

The default code highlighting relies on CodeRay, a fast syntax highlighting library written completely in Ruby. It currently supports c, cpp, css, delphi, groovy, html, java, javascript, json, php, python, rhtml, ruby, scheme, sql, xml and yaml languages.

You can highlight code in your wiki page using this syntax: