]> source.dussan.org Git - redmine.git/commitdiff
Line height is too large when previewing files with syntax highlighting if the line...
authorGo MAEDA <maeda@farend.jp>
Sun, 3 Feb 2019 22:34:08 +0000 (22:34 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 3 Feb 2019 22:34:08 +0000 (22:34 +0000)
Patch by Yuichi HARADA.

git-svn-id: http://svn.redmine.org/redmine/trunk@17847 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/syntax_highlighting.rb
test/helpers/application_helper_test.rb

index e2d47f2776e1e4558cf6b96ca622e9c481e019a2..53ae4b5ff5f08a0d3d951ee7f9c067d9d79bcb40 100644 (file)
@@ -76,6 +76,13 @@ module Redmine
         # Highlights +text+ as the content of +filename+
         # Should not return line numbers nor outer pre tag
         def highlight_by_filename(text, filename)
+          # TODO: Delete the following workaround for #30434 and
+          # test_syntax_highlight_should_normalize_line_endings in
+          # application_helper_test.rb when Rouge is improved to
+          # handle CRLF properly.
+          # See also: https://github.com/jneen/rouge/pull/1078
+          text = text.gsub(/\r\n?/, "\n")
+
           lexer =::Rouge::Lexer.guess_by_filename(filename)
           formatter = ::Rouge::Formatters::HTML.new
           ::Rouge.highlight(text, lexer, CustomHTMLLinewise.new(formatter))
index 5561e2f40568a5f9fc77d09ed69e6e3fcfcade7f..48304af254d93de07be20c08d1aa9039ee5fa7d8 100644 (file)
@@ -1123,6 +1123,10 @@ EXPECTED
     end
   end
 
+  def test_syntax_highlight_should_normalize_line_endings
+    assert_equal "line 1\nline 2\n", syntax_highlight("test.txt", "line 1\rline 2\r\n")
+  end
+
   def test_to_path_param
     assert_equal 'test1/test2', to_path_param('test1/test2')
     assert_equal 'test1/test2', to_path_param('/test1/test2/')