From b7cdeabbf68a62a3cb91ec0f0a6ded0ed34d1204 Mon Sep 17 00:00:00 2001 From: Walter Smith Date: Wed, 10 Oct 2012 14:07:42 -0700 Subject: [PATCH 1/2] Catch all Pygments errors An unrecognized language was generating a MentosError rather than a PythonError. Just catch anything that goes wrong in Pygments. --- lib/gollum/markup.rb | 4 ++-- test/test_markup.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index d1fa9fa0..2f27d6fa 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -558,12 +558,12 @@ module Gollum encoding ||= 'utf-8' begin hl_code = Pygments.highlight(code, :lexer => lang, :options => {:encoding => encoding.to_s}) - rescue ::RubyPython::PythonError + rescue hl_code = code end highlighted << hl_code end - + @codemap.each do |id, spec| body = spec[:output] || begin if (body = highlighted.shift.to_s).size > 0 diff --git a/test/test_markup.rb b/test/test_markup.rb index 3424e92a..285be397 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -534,6 +534,14 @@ np.array([[2,2],[1,3]],np.float) assert_equal %Q{

a\n

<p>a\n!rel</p>\n
\n}, output end + test "code block in unsupported language" do + @wiki.write_page("a", :markdown, "a\n```nonexistent\ncode\n```\nb", commit_details) + + page = @wiki.page("a") + output = page.formatted_data + assert_equal %Q{

a\ncode\nb

}, output + end + ######################################################################### # # Web Sequence Diagrams From d98547a33c09bd585a5903f562970802f05d6a92 Mon Sep 17 00:00:00 2001 From: Walter Smith Date: Wed, 10 Oct 2012 14:09:21 -0700 Subject: [PATCH 2/2] Fix lack of CoffeeScript livepreview Pygments calls it coffeescript, but Ace calls it coffee. --- .../gollum/livepreview/js/livepreview.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js b/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js index 8aefeb51..7317f4a1 100644 --- a/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js +++ b/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js @@ -195,12 +195,13 @@ var previewSet = function( text ) { }; // 'c', 'c++', 'cpp' are github specific and transformed to c_cpp for Ace. -var languages = [ 'c', 'c++', 'cpp', 'clojure', 'coffee', 'coldfusion', - 'csharp', 'css', 'diff', 'golang', 'groovy', 'haxe', 'html', - 'java', 'javascript', 'json', 'latex', 'less', 'liquid', - 'lua', 'markdown', 'ocaml', 'perl', 'pgsql', 'php', 'powershell', - 'python', 'ruby', 'scad', 'scala', 'scss', 'sh', 'sql', 'svg', - 'textile', 'text', 'xml', 'xquery', 'yaml' ]; +// 'coffeescript' is transformed to 'coffee' for Ace. +var languages = [ 'c', 'c++', 'cpp', 'clojure', 'coffee', + 'coffeescript', 'coldfusion', 'csharp', 'css', 'diff', 'golang', + 'groovy', 'haxe', 'html', 'java', 'javascript', 'json', 'latex', + 'less', 'liquid', 'lua', 'markdown', 'ocaml', 'perl', 'pgsql', 'php', + 'powershell', 'python', 'ruby', 'scad', 'scala', 'scss', 'sh', 'sql', + 'svg', 'textile', 'text', 'xml', 'xquery', 'yaml' ]; var staticHighlight = require( 'ace/ext/static_highlight' ); var githubTheme = require( 'ace/theme/github' ); @@ -303,6 +304,12 @@ var makePreviewHtml = function () { aceMode = 'c_cpp'; } + // Pygments's name for CoffeeScript is 'coffeescript', but Ace + // calls it 'coffee'. + if ( declaredLanguage === 'coffeescript' ) { + aceMode = 'coffee'; + } + if ( $.inArray( declaredLanguage, languages ) === -1 ) { // Unsupported language. skipped++;