From 1b624b479fdd9387ab54b453ac92e39d50eddd91 Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Sun, 26 Aug 2018 11:54:51 +0900 Subject: [PATCH] Replace syntax highlighter: CodeRay with Rouge --- Gemfile | 2 +- lib/redmine/syntax_highlighting.rb | 59 +++++--- .../javascripts/jstoolbar/jstoolbar-textile.min.js | 2 +- public/javascripts/jstoolbar/jstoolbar.js | 6 +- public/stylesheets/application.css | 167 +++++++++------------ public/stylesheets/rtl.css | 3 - test/helpers/application_helper_test.rb | 8 +- .../redmine/syntax_highlighting/coderay_test.rb | 37 ----- .../wiki_formatting/markdown_formatter_test.rb | 2 +- .../wiki_formatting/textile_formatter_test.rb | 4 +- 10 files changed, 124 insertions(+), 166 deletions(-) delete mode 100644 test/unit/lib/redmine/syntax_highlighting/coderay_test.rb diff --git a/Gemfile b/Gemfile index 69a86c716..89ea33a56 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ if Gem::Version.new(Bundler::VERSION) < Gem::Version.new('1.5.0') end gem "rails", "5.2.1" -gem "coderay", "~> 1.1.1" +gem "rouge", "~> 3.2.1" gem "request_store", "1.0.5" gem "mini_mime", "~> 1.0.1" gem "actionpack-xml_parser" diff --git a/lib/redmine/syntax_highlighting.rb b/lib/redmine/syntax_highlighting.rb index 49d9f4110..e2d47f277 100644 --- a/lib/redmine/syntax_highlighting.rb +++ b/lib/redmine/syntax_highlighting.rb @@ -52,42 +52,65 @@ module Redmine end end - module CodeRay - require 'coderay' + module Rouge + require 'rouge' - def self.retrieve_supported_languages - ::CodeRay::Scanners.list + - # Add CodeRay scanner aliases - ::CodeRay::Scanners.plugin_hash.keys.map(&:to_sym) - - # Remove internal CodeRay scanners - %w(debug default raydebug scanner).map(&:to_sym) - end - private_class_method :retrieve_supported_languages + # Customized formatter based on Rouge::Formatters::HTMLLinewise + # Syntax highlighting is completed within each line. + class CustomHTMLLinewise < ::Rouge::Formatter + def initialize(formatter) + @formatter = formatter + end - SUPPORTED_LANGUAGES = retrieve_supported_languages + def stream(tokens, &b) + token_lines(tokens) do |line| + line.each do |tok, val| + yield @formatter.span(tok, val) + end + yield "\n" + end + end + end class << self # Highlights +text+ as the content of +filename+ # Should not return line numbers nor outer pre tag def highlight_by_filename(text, filename) - language = ::CodeRay::FileType[filename] - language ? ::CodeRay.scan(text, language).html(:break_lines => true) : ERB::Util.h(text) + lexer =::Rouge::Lexer.guess_by_filename(filename) + formatter = ::Rouge::Formatters::HTML.new + ::Rouge.highlight(text, lexer, CustomHTMLLinewise.new(formatter)) end # Highlights +text+ using +language+ syntax # Should not return outer pre tag def highlight_by_language(text, language) - ::CodeRay.scan(text, language).html(:wrap => :span) + lexer = + find_lexer(language.to_s.downcase) || ::Rouge::Lexers::PlainText + ::Rouge.highlight(text, lexer, ::Rouge::Formatters::HTML) end def language_supported?(language) - SUPPORTED_LANGUAGES.include?(language.to_s.downcase.to_sym) - rescue - false + find_lexer(language.to_s.downcase) ? true : false + end + + private + # Alias names used by CodeRay and not supported by Rouge + LANG_ALIASES = { + 'delphi' => 'pascal', + 'cplusplus' => 'cpp', + 'ecmascript' => 'javascript', + 'ecma_script' => 'javascript', + 'java_script' => 'javascript', + 'xhtml' => 'html' + } + + def find_lexer(language) + ::Rouge::Lexer.find(language) || + ::Rouge::Lexer.find(LANG_ALIASES[language]) end end end end - SyntaxHighlighting.highlighter = 'CodeRay' + SyntaxHighlighting.highlighter = 'Rouge' end diff --git a/public/javascripts/jstoolbar/jstoolbar-textile.min.js b/public/javascripts/jstoolbar/jstoolbar-textile.min.js index e087d1cf2..f8d36edf4 100644 --- a/public/javascripts/jstoolbar/jstoolbar-textile.min.js +++ b/public/javascripts/jstoolbar/jstoolbar-textile.min.js @@ -1 +1 @@ -function jsToolBar(e){if(document.createElement&&e&&("undefined"!=typeof document.selection||"undefined"!=typeof e.setSelectionRange)){if(this.textarea=e,this.editor=document.createElement("div"),this.editor.className="jstEditor",this.textarea.parentNode.insertBefore(this.editor,this.textarea),this.editor.appendChild(this.textarea),this.toolbar=document.createElement("div"),this.toolbar.className="jstElements",this.editor.parentNode.insertBefore(this.toolbar,this.editor),this.editor.addEventListener&&navigator.appVersion.match(/\bMSIE\b/)){this.handle=document.createElement("div"),this.handle.className="jstHandle";var t=this.resizeDragStart,n=this;this.handle.addEventListener("mousedown",function(e){t.call(n,e)},!1),window.addEventListener("unload",function(){n.handle.parentNode.removeChild(n.handle);delete n.handle},!1),this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling)}this.context=null,this.toolNodes={}}}function jsButton(e,t,n,o){"undefined"==typeof jsToolBar.strings?this.title=e||null:this.title=jsToolBar.strings[e]||e||null,this.fn=t||function(){},this.scope=n||null,this.className=o||null}function jsSpace(e){this.id=e||null,this.width=null}function jsCombo(e,t,n,o,i){this.title=e||null,this.options=t||null,this.scope=n||null,this.fn=o||function(){},this.className=i||null}jsButton.prototype.draw=function(){if(!this.scope)return null;var e=document.createElement("button");e.setAttribute("type","button"),e.tabIndex=200,this.className&&(e.className=this.className),e.title=this.title;var t=document.createElement("span");if(t.appendChild(document.createTextNode(this.title)),e.appendChild(t),void 0!=this.icon&&(e.style.backgroundImage="url("+this.icon+")"),"function"==typeof this.fn){var n=this;e.onclick=function(){try{n.fn.apply(n.scope,arguments)}catch(e){}return!1}}return e},jsSpace.prototype.draw=function(){var e=document.createElement("span");return this.id&&(e.id=this.id),e.appendChild(document.createTextNode(String.fromCharCode(160))),e.className="jstSpacer",this.width&&(e.style.marginRight=this.width+"px"),e},jsCombo.prototype.draw=function(){if(!this.scope||!this.options)return null;var e=document.createElement("select");this.className&&(e.className=className),e.title=this.title;for(var t in this.options){var n=document.createElement("option");n.value=t,n.appendChild(document.createTextNode(this.options[t])),e.appendChild(n)}var o=this;return e.onchange=function(){try{o.fn.call(o.scope,this.value)}catch(e){alert(e)}return!1},e},jsToolBar.prototype={base_url:"",mode:"wiki",elements:{},help_link:"",getMode:function(){return this.mode},setMode:function(e){this.mode=e||"wiki"},switchMode:function(e){e=e||"wiki",this.draw(e)},setHelpLink:function(e){this.help_link=e},button:function(e){var t=this.elements[e];if("function"!=typeof t.fn[this.mode])return null;var n=new jsButton(t.title,t.fn[this.mode],this,"jstb_"+e);return void 0!=t.icon&&(n.icon=t.icon),n},space:function(e){var t=new jsSpace(e);return void 0!==this.elements[e].width&&(t.width=this.elements[e].width),t},combo:function(e){var t=this.elements[e],n=t[this.mode].list.length;if("function"!=typeof t[this.mode].fn||0==n)return null;for(var o={},i=0;n>i;i++){var s=t[this.mode].list[i];o[s]=t.options[s]}return new jsCombo(t.title,o,this,t[this.mode].fn)},draw:function(e){for(this.setMode(e);this.toolbar.hasChildNodes();)this.toolbar.removeChild(this.toolbar.firstChild);this.toolNodes={};var t,n,o;for(var i in this.elements){t=this.elements[i];var s=void 0==t.type||""==t.type||void 0!=t.disabled&&t.disabled||void 0!=t.context&&null!=t.context&&t.context!=this.context;s||"function"!=typeof this[t.type]||(n=this[t.type](i),n&&(o=n.draw()),o&&(this.toolNodes[i]=o,this.toolbar.appendChild(o)))}},singleTag:function(e,t){e=e||null,t=t||e,e&&t&&this.encloseSelection(e,t)},encloseLineSelection:function(e,t,n){this.textarea.focus(),e=e||"",t=t||"";var o,i,s,l,a,r;if("undefined"!=typeof document.selection?s=document.selection.createRange().text:"undefined"!=typeof this.textarea.setSelectionRange&&(o=this.textarea.selectionStart,i=this.textarea.selectionEnd,l=this.textarea.scrollTop,o=this.textarea.value.substring(0,o).replace(/[^\r\n]*$/g,"").length,i=this.textarea.value.length-this.textarea.value.substring(i,this.textarea.value.length).replace(/^[^\r\n]*/,"").length,s=this.textarea.value.substring(o,i)),s.match(/ $/)&&(s=s.substring(0,s.length-1),t+=" "),r="function"==typeof n?s?n.call(this,s):n(""):s?s:"",a=e+r+t,"undefined"!=typeof document.selection){document.selection.createRange().text=a;var c=this.textarea.createTextRange();c.collapse(!1),c.move("character",-t.length),c.select()}else"undefined"!=typeof this.textarea.setSelectionRange&&(this.textarea.value=this.textarea.value.substring(0,o)+a+this.textarea.value.substring(i),s?this.textarea.setSelectionRange(o+a.length,o+a.length):this.textarea.setSelectionRange(o+e.length,o+e.length),this.textarea.scrollTop=l)},encloseSelection:function(e,t,n){this.textarea.focus(),e=e||"",t=t||"";var o,i,s,l,a,r;if("undefined"!=typeof document.selection?s=document.selection.createRange().text:"undefined"!=typeof this.textarea.setSelectionRange&&(o=this.textarea.selectionStart,i=this.textarea.selectionEnd,l=this.textarea.scrollTop,s=this.textarea.value.substring(o,i),o>0&&this.textarea.value.substr(o-1, 1).match(/\S/)&&(e=" "+e),this.textarea.value.substr(i, 1).match(/\S/)&&(t=t+" ")),s.match(/ $/)&&(s=s.substring(0,s.length-1),t+=" "),r="function"==typeof n?s?n.call(this,s):n(""):s?s:"",a=e+r+t,"undefined"!=typeof document.selection){document.selection.createRange().text=a;var c=this.textarea.createTextRange();c.collapse(!1),c.move("character",-t.length),c.select()}else"undefined"!=typeof this.textarea.setSelectionRange&&(this.textarea.value=this.textarea.value.substring(0,o)+a+this.textarea.value.substring(i),s?this.textarea.setSelectionRange(o+a.length,o+a.length):this.textarea.setSelectionRange(o+e.length,o+e.length),this.textarea.scrollTop=l)},stripBaseURL:function(e){if(""!=this.base_url){var t=e.indexOf(this.base_url);0==t&&(e=e.substr(this.base_url.length))}return e}},jsToolBar.prototype.resizeSetStartH=function(){this.dragStartH=this.textarea.offsetHeight+0},jsToolBar.prototype.resizeDragStart=function(e){var t=this;this.dragStartY=e.clientY,this.resizeSetStartH(),document.addEventListener("mousemove",this.dragMoveHdlr=function(e){t.resizeDragMove(e)},!1),document.addEventListener("mouseup",this.dragStopHdlr=function(e){t.resizeDragStop(e)},!1)},jsToolBar.prototype.resizeDragMove=function(e){this.textarea.style.height=this.dragStartH+e.clientY-this.dragStartY+"px"},jsToolBar.prototype.resizeDragStop=function(e){document.removeEventListener("mousemove",this.dragMoveHdlr,!1),document.removeEventListener("mouseup",this.dragStopHdlr,!1)},jsToolBar.prototype.precodeMenu=function(e){for(var t=["c","clojure","cpp","css","delphi","diff","erb","go","groovy","haml","html","java","javascript","json","lua","php","python","ruby","sass","sql","taskpaper","text","xml","yaml"],n=$(""),o=0;o").text(t[o]).appendTo(n).mousedown(function(){e($(this).text())});return $("body").append(n),n.menu().width(150).position({my:"left top",at:"left bottom",of:this.toolNodes.precode}),$(document).on("mousedown",function(){n.remove()}),!1},jsToolBar.prototype.elements.strong={type:"button",title:"Strong",fn:{wiki:function(){this.singleTag("*")}}},jsToolBar.prototype.elements.em={type:"button",title:"Italic",fn:{wiki:function(){this.singleTag("_")}}},jsToolBar.prototype.elements.ins={type:"button",title:"Underline",fn:{wiki:function(){this.singleTag("+")}}},jsToolBar.prototype.elements.del={type:"button",title:"Deleted",fn:{wiki:function(){this.singleTag("-")}}},jsToolBar.prototype.elements.code={type:"button",title:"Code",fn:{wiki:function(){this.singleTag("@")}}},jsToolBar.prototype.elements.space1={type:"space"},jsToolBar.prototype.elements.h1={type:"button",title:"Heading 1",fn:{wiki:function(){this.encloseLineSelection("h1. ","",function(e){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.h2={type:"button",title:"Heading 2",fn:{wiki:function(){this.encloseLineSelection("h2. ","",function(e){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.h3={type:"button",title:"Heading 3",fn:{wiki:function(){this.encloseLineSelection("h3. ","",function(e){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.space2={type:"space"},jsToolBar.prototype.elements.ul={type:"button",title:"Unordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),e.replace(/(\n|^)[#-]?\s*/g,"$1* ")})}}},jsToolBar.prototype.elements.ol={type:"button",title:"Ordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),e.replace(/(\n|^)[*-]?\s*/g,"$1# ")})}}},jsToolBar.prototype.elements.space3={type:"space"},jsToolBar.prototype.elements.bq={type:"button",title:"Quote",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),e.replace(/(\n|^) *([^\n]*)/g,"$1> $2")})}}},jsToolBar.prototype.elements.unbq={type:"button",title:"Unquote",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),e.replace(/(\n|^) *[>]? *([^\n]*)/g,"$1$2")})}}},jsToolBar.prototype.elements.pre={type:"button",title:"Preformatted text",fn:{wiki:function(){this.encloseLineSelection("
\n","\n
")}}},jsToolBar.prototype.elements.precode={type:"button",title:"Highlighted code",fn:{wiki:function(){var e=this;this.precodeMenu(function(t){e.encloseLineSelection('
\n',"\n
\n")})}}},jsToolBar.prototype.elements.space4={type:"space"},jsToolBar.prototype.elements.link={type:"button",title:"Wiki link",fn:{wiki:function(){this.encloseSelection("[[","]]")}}},jsToolBar.prototype.elements.img={type:"button",title:"Image",fn:{wiki:function(){this.encloseSelection("!","!")}}},jsToolBar.prototype.elements.space5={type:"space"},jsToolBar.prototype.elements.help={type:"button",title:"Help",fn:{wiki:function(){window.open(this.help_link,"","resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes")}}}; +function jsToolBar(e){if(document.createElement&&e&&("undefined"!=typeof document.selection||"undefined"!=typeof e.setSelectionRange)){if(this.textarea=e,this.editor=document.createElement("div"),this.editor.className="jstEditor",this.textarea.parentNode.insertBefore(this.editor,this.textarea),this.editor.appendChild(this.textarea),this.toolbar=document.createElement("div"),this.toolbar.className="jstElements",this.editor.parentNode.insertBefore(this.toolbar,this.editor),this.editor.addEventListener&&navigator.appVersion.match(/\bMSIE\b/)){this.handle=document.createElement("div"),this.handle.className="jstHandle";var t=this.resizeDragStart,n=this;this.handle.addEventListener("mousedown",function(e){t.call(n,e)},!1),window.addEventListener("unload",function(){n.handle.parentNode.removeChild(n.handle);delete n.handle},!1),this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling)}this.context=null,this.toolNodes={}}}function jsButton(e,t,n,o){"undefined"==typeof jsToolBar.strings?this.title=e||null:this.title=jsToolBar.strings[e]||e||null,this.fn=t||function(){},this.scope=n||null,this.className=o||null}function jsSpace(e){this.id=e||null,this.width=null}function jsCombo(e,t,n,o,i){this.title=e||null,this.options=t||null,this.scope=n||null,this.fn=o||function(){},this.className=i||null}jsButton.prototype.draw=function(){if(!this.scope)return null;var e=document.createElement("button");e.setAttribute("type","button"),e.tabIndex=200,this.className&&(e.className=this.className),e.title=this.title;var t=document.createElement("span");if(t.appendChild(document.createTextNode(this.title)),e.appendChild(t),void 0!=this.icon&&(e.style.backgroundImage="url("+this.icon+")"),"function"==typeof this.fn){var n=this;e.onclick=function(){try{n.fn.apply(n.scope,arguments)}catch(e){}return!1}}return e},jsSpace.prototype.draw=function(){var e=document.createElement("span");return this.id&&(e.id=this.id),e.appendChild(document.createTextNode(String.fromCharCode(160))),e.className="jstSpacer",this.width&&(e.style.marginRight=this.width+"px"),e},jsCombo.prototype.draw=function(){if(!this.scope||!this.options)return null;var e=document.createElement("select");this.className&&(e.className=className),e.title=this.title;for(var t in this.options){var n=document.createElement("option");n.value=t,n.appendChild(document.createTextNode(this.options[t])),e.appendChild(n)}var o=this;return e.onchange=function(){try{o.fn.call(o.scope,this.value)}catch(e){alert(e)}return!1},e},jsToolBar.prototype={base_url:"",mode:"wiki",elements:{},help_link:"",getMode:function(){return this.mode},setMode:function(e){this.mode=e||"wiki"},switchMode:function(e){e=e||"wiki",this.draw(e)},setHelpLink:function(e){this.help_link=e},button:function(e){var t=this.elements[e];if("function"!=typeof t.fn[this.mode])return null;var n=new jsButton(t.title,t.fn[this.mode],this,"jstb_"+e);return void 0!=t.icon&&(n.icon=t.icon),n},space:function(e){var t=new jsSpace(e);return void 0!==this.elements[e].width&&(t.width=this.elements[e].width),t},combo:function(e){var t=this.elements[e],n=t[this.mode].list.length;if("function"!=typeof t[this.mode].fn||0==n)return null;for(var o={},i=0;n>i;i++){var s=t[this.mode].list[i];o[s]=t.options[s]}return new jsCombo(t.title,o,this,t[this.mode].fn)},draw:function(e){for(this.setMode(e);this.toolbar.hasChildNodes();)this.toolbar.removeChild(this.toolbar.firstChild);this.toolNodes={};var t,n,o;for(var i in this.elements){t=this.elements[i];var s=void 0==t.type||""==t.type||void 0!=t.disabled&&t.disabled||void 0!=t.context&&null!=t.context&&t.context!=this.context;s||"function"!=typeof this[t.type]||(n=this[t.type](i),n&&(o=n.draw()),o&&(this.toolNodes[i]=o,this.toolbar.appendChild(o)))}},singleTag:function(e,t){e=e||null,t=t||e,e&&t&&this.encloseSelection(e,t)},encloseLineSelection:function(e,t,n){this.textarea.focus(),e=e||"",t=t||"";var o,i,s,l,a,r;if("undefined"!=typeof document.selection?s=document.selection.createRange().text:"undefined"!=typeof this.textarea.setSelectionRange&&(o=this.textarea.selectionStart,i=this.textarea.selectionEnd,l=this.textarea.scrollTop,o=this.textarea.value.substring(0,o).replace(/[^\r\n]*$/g,"").length,i=this.textarea.value.length-this.textarea.value.substring(i,this.textarea.value.length).replace(/^[^\r\n]*/,"").length,s=this.textarea.value.substring(o,i)),s.match(/ $/)&&(s=s.substring(0,s.length-1),t+=" "),r="function"==typeof n?s?n.call(this,s):n(""):s?s:"",a=e+r+t,"undefined"!=typeof document.selection){document.selection.createRange().text=a;var c=this.textarea.createTextRange();c.collapse(!1),c.move("character",-t.length),c.select()}else"undefined"!=typeof this.textarea.setSelectionRange&&(this.textarea.value=this.textarea.value.substring(0,o)+a+this.textarea.value.substring(i),s?this.textarea.setSelectionRange(o+a.length,o+a.length):this.textarea.setSelectionRange(o+e.length,o+e.length),this.textarea.scrollTop=l)},encloseSelection:function(e,t,n){this.textarea.focus(),e=e||"",t=t||"";var o,i,s,l,a,r;if("undefined"!=typeof document.selection?s=document.selection.createRange().text:"undefined"!=typeof this.textarea.setSelectionRange&&(o=this.textarea.selectionStart,i=this.textarea.selectionEnd,l=this.textarea.scrollTop,s=this.textarea.value.substring(o,i),o>0&&this.textarea.value.substr(o-1, 1).match(/\S/)&&(e=" "+e),this.textarea.value.substr(i, 1).match(/\S/)&&(t=t+" ")),s.match(/ $/)&&(s=s.substring(0,s.length-1),t+=" "),r="function"==typeof n?s?n.call(this,s):n(""):s?s:"",a=e+r+t,"undefined"!=typeof document.selection){document.selection.createRange().text=a;var c=this.textarea.createTextRange();c.collapse(!1),c.move("character",-t.length),c.select()}else"undefined"!=typeof this.textarea.setSelectionRange&&(this.textarea.value=this.textarea.value.substring(0,o)+a+this.textarea.value.substring(i),s?this.textarea.setSelectionRange(o+a.length,o+a.length):this.textarea.setSelectionRange(o+e.length,o+e.length),this.textarea.scrollTop=l)},stripBaseURL:function(e){if(""!=this.base_url){var t=e.indexOf(this.base_url);0==t&&(e=e.substr(this.base_url.length))}return e}},jsToolBar.prototype.resizeSetStartH=function(){this.dragStartH=this.textarea.offsetHeight+0},jsToolBar.prototype.resizeDragStart=function(e){var t=this;this.dragStartY=e.clientY,this.resizeSetStartH(),document.addEventListener("mousemove",this.dragMoveHdlr=function(e){t.resizeDragMove(e)},!1),document.addEventListener("mouseup",this.dragStopHdlr=function(e){t.resizeDragStop(e)},!1)},jsToolBar.prototype.resizeDragMove=function(e){this.textarea.style.height=this.dragStartH+e.clientY-this.dragStartY+"px"},jsToolBar.prototype.resizeDragStop=function(e){document.removeEventListener("mousemove",this.dragMoveHdlr,!1),document.removeEventListener("mouseup",this.dragStopHdlr,!1)},jsToolBar.prototype.precodeMenu=function(e){for(var t=["c","clojure","cpp","css","delphi","diff","erb","go","groovy","haml","html","java","javascript","json","lua","pascal","php","python","ruby","sass","sql","text","xml","yaml"],n=$(""),o=0;o").text(t[o]).appendTo(n).mousedown(function(){e($(this).text())});return $("body").append(n),n.menu().width(150).position({my:"left top",at:"left bottom",of:this.toolNodes.precode}),$(document).on("mousedown",function(){n.remove()}),!1},jsToolBar.prototype.elements.strong={type:"button",title:"Strong",fn:{wiki:function(){this.singleTag("*")}}},jsToolBar.prototype.elements.em={type:"button",title:"Italic",fn:{wiki:function(){this.singleTag("_")}}},jsToolBar.prototype.elements.ins={type:"button",title:"Underline",fn:{wiki:function(){this.singleTag("+")}}},jsToolBar.prototype.elements.del={type:"button",title:"Deleted",fn:{wiki:function(){this.singleTag("-")}}},jsToolBar.prototype.elements.code={type:"button",title:"Code",fn:{wiki:function(){this.singleTag("@")}}},jsToolBar.prototype.elements.space1={type:"space"},jsToolBar.prototype.elements.h1={type:"button",title:"Heading 1",fn:{wiki:function(){this.encloseLineSelection("h1. ","",function(e){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.h2={type:"button",title:"Heading 2",fn:{wiki:function(){this.encloseLineSelection("h2. ","",function(e){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.h3={type:"button",title:"Heading 3",fn:{wiki:function(){this.encloseLineSelection("h3. ","",function(e){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.space2={type:"space"},jsToolBar.prototype.elements.ul={type:"button",title:"Unordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),e.replace(/(\n|^)[#-]?\s*/g,"$1* ")})}}},jsToolBar.prototype.elements.ol={type:"button",title:"Ordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),e.replace(/(\n|^)[*-]?\s*/g,"$1# ")})}}},jsToolBar.prototype.elements.space3={type:"space"},jsToolBar.prototype.elements.bq={type:"button",title:"Quote",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),e.replace(/(\n|^) *([^\n]*)/g,"$1> $2")})}}},jsToolBar.prototype.elements.unbq={type:"button",title:"Unquote",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),e.replace(/(\n|^) *[>]? *([^\n]*)/g,"$1$2")})}}},jsToolBar.prototype.elements.pre={type:"button",title:"Preformatted text",fn:{wiki:function(){this.encloseLineSelection("
\n","\n
")}}},jsToolBar.prototype.elements.precode={type:"button",title:"Highlighted code",fn:{wiki:function(){var e=this;this.precodeMenu(function(t){e.encloseLineSelection('
\n',"\n
\n")})}}},jsToolBar.prototype.elements.space4={type:"space"},jsToolBar.prototype.elements.link={type:"button",title:"Wiki link",fn:{wiki:function(){this.encloseSelection("[[","]]")}}},jsToolBar.prototype.elements.img={type:"button",title:"Image",fn:{wiki:function(){this.encloseSelection("!","!")}}},jsToolBar.prototype.elements.space5={type:"space"},jsToolBar.prototype.elements.help={type:"button",title:"Help",fn:{wiki:function(){window.open(this.help_link,"","resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes")}}}; diff --git a/public/javascripts/jstoolbar/jstoolbar.js b/public/javascripts/jstoolbar/jstoolbar.js index bbda5f8b8..e42b240b8 100644 --- a/public/javascripts/jstoolbar/jstoolbar.js +++ b/public/javascripts/jstoolbar/jstoolbar.js @@ -380,10 +380,10 @@ jsToolBar.prototype.resizeDragStop = function(event) { /* Code highlighting menu */ jsToolBar.prototype.precodeMenu = function(fn){ - var codeRayLanguages = ["c", "clojure", "cpp", "css", "delphi", "diff", "erb", "go", "groovy", "haml", "html", "java", "javascript", "json", "lua", "php", "python", "ruby", "sass", "sql", "taskpaper", "text", "xml", "yaml"]; + var hlLanguages = ["c", "clojure", "cpp", "css", "diff", "erb", "go", "groovy", "haml", "html", "java", "javascript", "json", "lua", "pascal", "php", "python", "ruby", "sass", "sql", "text", "xml", "yaml"]; var menu = $("
    "); - for (var i = 0; i < codeRayLanguages.length; i++) { - $("
  • ").text(codeRayLanguages[i]).appendTo(menu).mousedown(function(){ + for (var i = 0; i < hlLanguages.length; i++) { + $("
  • ").text(hlLanguages[i]).appendTo(menu).mousedown(function(){ fn($(this).text()); }); } diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 6abf7788c..3cc47f54a 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1396,102 +1396,77 @@ img.filecontent.image {background-image: url(../images/transparent.png);} .ui-datepicker-title select {width:70px !important; margin-top:-2px !important; margin-right:4px !important;} -/************* CodeRay styles *************/ -.syntaxhl div {display: inline;} -.syntaxhl .code pre { overflow: auto } - -.syntaxhl .annotation { color:#007 } -.syntaxhl .attribute-name { color:#b48 } -.syntaxhl .attribute-value { color:#700 } -.syntaxhl .binary { color:#549 } -.syntaxhl .binary .char { color:#325 } -.syntaxhl .binary .delimiter { color:#325 } -.syntaxhl .char { color:#D20 } -.syntaxhl .char .content { color:#D20 } -.syntaxhl .char .delimiter { color:#710 } -.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 .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 .docstring { color:#D42; } -.syntaxhl .doctype { color:#34b } -.syntaxhl .done { text-decoration: line-through; color: gray } -.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 .function .delimiter { color:#059 } -.syntaxhl .function .content { color:#037 } -.syntaxhl .global-variable { color:#d70 } -.syntaxhl .hex { color:#02b } -.syntaxhl .id { color:#33D; font-weight:bold } -.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 .imaginary { color:#f00 } -.syntaxhl .important { color:#D00 } -.syntaxhl .key { color: #606 } -.syntaxhl .key .char { color: #60f } -.syntaxhl .key .delimiter { color: #404 } -.syntaxhl .keyword { color:#080; font-weight:bold } -.syntaxhl .label { color:#970; font-weight:bold } -.syntaxhl .local-variable { color:#950 } -.syntaxhl .map .content { color:#808 } -.syntaxhl .map .delimiter { color:#40A} -.syntaxhl .map { background-color:hsla(200,100%,50%,0.06); } -.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:#0a8; font-weight:bold } -.syntaxhl .preprocessor { color:#579 } -.syntaxhl .pseudo-class { color:#00C; font-weight:bold } -.syntaxhl .regexp { background-color:hsla(300,100%,50%,0.06); } -.syntaxhl .regexp .content { color:#808 } -.syntaxhl .regexp .delimiter { color:#404 } -.syntaxhl .regexp .modifier { color:#C2C } -.syntaxhl .reserved { color:#080; font-weight:bold } -.syntaxhl .shell { background-color:hsla(120,100%,50%,0.06); } -.syntaxhl .shell .content { color:#2B2 } -.syntaxhl .shell .delimiter { color:#161 } -.syntaxhl .string { background-color:hsla(0,100%,50%,0.05); } -.syntaxhl .string .char { color: #b0b } -.syntaxhl .string .content { color: #D20 } -.syntaxhl .string .delimiter { color: #710 } -.syntaxhl .string .modifier { color: #E40 } -.syntaxhl .symbol { color:#A60 } -.syntaxhl .symbol .content { color:#A60 } -.syntaxhl .symbol .delimiter { color:#740 } -.syntaxhl .tag { color:#070; font-weight:bold } -.syntaxhl .type { color:#339; font-weight:bold } -.syntaxhl .value { color: #088 } -.syntaxhl .variable { color:#037 } - -.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 .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 } +/************* Rouge styles *************/ +/* generated by: pygmentize -f html -a .syntaxhl -S colorful */ +.syntaxhl .hll { background-color: #ffffcc } +.syntaxhl { background: #fafafa; } +.syntaxhl .c { color: #888888 } /* Comment */ +.syntaxhl .err { color: #FF0000; background-color: #FFAAAA } /* Error */ +.syntaxhl .k { color: #008800; font-weight: bold } /* Keyword */ +.syntaxhl .o { color: #333333 } /* Operator */ +.syntaxhl .ch { color: #888888 } /* Comment.Hashbang */ +.syntaxhl .cm { color: #888888 } /* Comment.Multiline */ +.syntaxhl .cp { color: #557799 } /* Comment.Preproc */ +.syntaxhl .cpf { color: #888888 } /* Comment.PreprocFile */ +.syntaxhl .c1 { color: #888888 } /* Comment.Single */ +.syntaxhl .cs { color: #cc0000; font-weight: bold } /* Comment.Special */ +.syntaxhl .gd { color: #A00000 } /* Generic.Deleted */ +.syntaxhl .ge { font-style: italic } /* Generic.Emph */ +.syntaxhl .gr { color: #FF0000 } /* Generic.Error */ +.syntaxhl .gh { color: #000080; font-weight: bold } /* Generic.Heading */ +.syntaxhl .gi { color: #00A000 } /* Generic.Inserted */ +.syntaxhl .go { color: #888888 } /* Generic.Output */ +.syntaxhl .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ +.syntaxhl .gs { font-weight: bold } /* Generic.Strong */ +.syntaxhl .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ +.syntaxhl .gt { color: #0044DD } /* Generic.Traceback */ +.syntaxhl .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ +.syntaxhl .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ +.syntaxhl .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ +.syntaxhl .kp { color: #003388; font-weight: bold } /* Keyword.Pseudo */ +.syntaxhl .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ +.syntaxhl .kt { color: #333399; font-weight: bold } /* Keyword.Type */ +.syntaxhl .m { color: #6600EE; font-weight: bold } /* Literal.Number */ +.syntaxhl .s { background-color: #fff0f0 } /* Literal.String */ +.syntaxhl .na { color: #0000CC } /* Name.Attribute */ +.syntaxhl .nb { color: #007020 } /* Name.Builtin */ +.syntaxhl .nc { color: #BB0066; font-weight: bold } /* Name.Class */ +.syntaxhl .no { color: #003366; font-weight: bold } /* Name.Constant */ +.syntaxhl .nd { color: #555555; font-weight: bold } /* Name.Decorator */ +.syntaxhl .ni { color: #880000; font-weight: bold } /* Name.Entity */ +.syntaxhl .ne { color: #FF0000; font-weight: bold } /* Name.Exception */ +.syntaxhl .nf { color: #0066BB; font-weight: bold } /* Name.Function */ +.syntaxhl .nl { color: #997700; font-weight: bold } /* Name.Label */ +.syntaxhl .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ +.syntaxhl .nt { color: #007700 } /* Name.Tag */ +.syntaxhl .nv { color: #996633 } /* Name.Variable */ +.syntaxhl .ow { color: #000000; font-weight: bold } /* Operator.Word */ +.syntaxhl .w { color: #bbbbbb } /* Text.Whitespace */ +.syntaxhl .mb { color: #6600EE; font-weight: bold } /* Literal.Number.Bin */ +.syntaxhl .mf { color: #6600EE; font-weight: bold } /* Literal.Number.Float */ +.syntaxhl .mh { color: #005588; font-weight: bold } /* Literal.Number.Hex */ +.syntaxhl .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ +.syntaxhl .mo { color: #4400EE; font-weight: bold } /* Literal.Number.Oct */ +.syntaxhl .sa { background-color: #fff0f0 } /* Literal.String.Affix */ +.syntaxhl .sb { background-color: #fff0f0 } /* Literal.String.Backtick */ +.syntaxhl .sc { color: #0044DD } /* Literal.String.Char */ +.syntaxhl .dl { background-color: #fff0f0 } /* Literal.String.Delimiter */ +.syntaxhl .sd { color: #DD4422 } /* Literal.String.Doc */ +.syntaxhl .s2 { background-color: #fff0f0 } /* Literal.String.Double */ +.syntaxhl .se { color: #666666; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */ +.syntaxhl .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */ +.syntaxhl .si { background-color: #eeeeee } /* Literal.String.Interpol */ +.syntaxhl .sx { color: #DD2200; background-color: #fff0f0 } /* Literal.String.Other */ +.syntaxhl .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */ +.syntaxhl .s1 { background-color: #fff0f0 } /* Literal.String.Single */ +.syntaxhl .ss { color: #AA6600 } /* Literal.String.Symbol */ +.syntaxhl .bp { color: #007020 } /* Name.Builtin.Pseudo */ +.syntaxhl .fm { color: #0066BB; font-weight: bold } /* Name.Function.Magic */ +.syntaxhl .vc { color: #336699 } /* Name.Variable.Class */ +.syntaxhl .vg { color: #dd7700; font-weight: bold } /* Name.Variable.Global */ +.syntaxhl .vi { color: #3333BB } /* Name.Variable.Instance */ +.syntaxhl .vm { color: #996633 } /* Name.Variable.Magic */ +.syntaxhl .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ /***** Media print specific styles *****/ @media print { diff --git a/public/stylesheets/rtl.css b/public/stylesheets/rtl.css index 4063e21ce..ec3ea20ba 100644 --- a/public/stylesheets/rtl.css +++ b/public/stylesheets/rtl.css @@ -373,9 +373,6 @@ td.username img.gravatar {margin:0 0 0 0.5em; } /* Custom JQuery styles */ .ui-datepicker-title select {margin-left:4px !important; margin-right:0 !important;} -/************* CodeRay styles *************/ -.syntaxhl .line-numbers {margin:0px 0px 0px 5px;} - /***** Media print specific styles *****/ @media print { } diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index aa403be46..25a75d852 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -1062,14 +1062,14 @@ EXPECTED def test_syntax_highlight raw = <<-RAW -
    
    -# Some ruby code here
    +
    
    +/* Hello */
    +document.write("Hello World!");
     
    RAW expected = <<-EXPECTED -
    # Some ruby code here
    -
    +
    /* Hello */document.write(\"Hello World!\");
    EXPECTED assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') diff --git a/test/unit/lib/redmine/syntax_highlighting/coderay_test.rb b/test/unit/lib/redmine/syntax_highlighting/coderay_test.rb deleted file mode 100644 index 1a2714b16..000000000 --- a/test/unit/lib/redmine/syntax_highlighting/coderay_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -# Redmine - project management software -# Copyright (C) 2006-2017 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -require File.expand_path('../../../../../test_helper', __FILE__) - -class Redmine::SyntaxHighlighting::CodeRayTest < ActiveSupport::TestCase - def test_retrieve_supported_languages_should_return_array_of_symbols - assert_kind_of Array, Redmine::SyntaxHighlighting::CodeRay.send(:retrieve_supported_languages) - assert_kind_of Symbol, Redmine::SyntaxHighlighting::CodeRay.send(:retrieve_supported_languages).first - end - - def test_retrieve_supported_languages_should_return_array_of_symbols_holding_languages - assert_includes Redmine::SyntaxHighlighting::CodeRay.send(:retrieve_supported_languages), :ruby - end - - def test_retrieve_supported_languages_should_return_array_of_symbols_holding_languages_aliases - assert_includes Redmine::SyntaxHighlighting::CodeRay.send(:retrieve_supported_languages), :javascript - end - - def test_retrieve_supported_languages_should_return_array_of_symbols_not_holding_internal_languages - refute_includes Redmine::SyntaxHighlighting::CodeRay.send(:retrieve_supported_languages), :default - end -end diff --git a/test/unit/lib/redmine/wiki_formatting/markdown_formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/markdown_formatter_test.rb index 54c484567..1ad76d69d 100644 --- a/test/unit/lib/redmine/wiki_formatting/markdown_formatter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/markdown_formatter_test.rb @@ -66,7 +66,7 @@ end ~~~ STR assert_select_in @formatter.new(text).to_html, 'pre code.ruby.syntaxhl' do - assert_select 'span.keyword', :text => 'def' + assert_select 'span.k', :text => 'def' end end diff --git a/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb index 712bc5000..cc31a4c80 100644 --- a/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb @@ -547,9 +547,9 @@ STR def test_should_allow_valid_language_class_attribute_on_code_tags # language name is double-quoted - assert_html_output({"test" => "test"}, false) + assert_html_output({"test" => "test"}, false) # language name is single-quoted - assert_html_output({"test" => "test"}, false) + assert_html_output({"test" => "test"}, false) end def test_should_not_allow_valid_language_class_attribute_on_non_code_offtags -- 2.14.3 (Apple Git-98)