Defect #28793

Redmine replaces tabs with spaces in code blocks

Added by Anton Shepelev over 3 years ago. Updated over 1 year ago.

Status:ConfirmedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Text formatting
Target version:-
Resolution: Affected version:3.4.4

Description

Regardless of whether I use Markdown or Textile, Redmine always replaces tabs with spaces in code blocks, which makes the code read-only, i.e. one cannot copy and paste it into their program, so I have to attach source files to issues or send them in separate e-mails.

The underlying Markdown and Textile text is correct but is rendered into HTML wrong.

Code blocks should present code as it is written: spaces should be spaces and tabs should be tabs.

My Redmine environment:

Environment:
  Redmine version                3.4.4.stable
  Ruby version                   2.3.3-p222 (2016-11-21) [i386-mingw32]
  Rails version                  4.2.8
  Environment                    production
  Database adapter               Mysql2
SCM:
  Subversion                     1.8.16
  Filesystem                     
Redmine plugins:
  no plugin installed


Related issues

Duplicated by Redmine - Defect #33707: Highlighted code with 'diff' format converts tabs to spac... Closed

History

#1 Updated by Go MAEDA over 1 year ago

  • Duplicated by Defect #33707: Highlighted code with 'diff' format converts tabs to spaces, which breaks IDEs added

#2 Updated by Go MAEDA over 1 year ago

  • Status changed from New to Confirmed

#3 Updated by Go MAEDA over 1 year ago

The behavior of Textile formatter can be changed with the following patch, but I think it is not easy to change the behavior of Markdown formatter because is done in Redcarpet gem.

diff --git a/lib/redmine/wiki_formatting/textile/redcloth3.rb b/lib/redmine/wiki_formatting/textile/redcloth3.rb
index 92c6e29d0..374e3c046 100644
--- a/lib/redmine/wiki_formatting/textile/redcloth3.rb
+++ b/lib/redmine/wiki_formatting/textile/redcloth3.rb
@@ -1017,7 +1017,6 @@ class RedCloth3 < String
         # normalize line breaks
         text.gsub!( /\r\n/, "\n" )
         text.gsub!( /\r/, "\n" )
-        text.gsub!( /\t/, '    ' )
         text.gsub!( /^ +$/, '' )
         text.gsub!( /\n{3,}/, "\n\n" )
         text.gsub!( /"$/, "\" " )

#4 Updated by Anton Shepelev over 1 year ago

Go MAEDA:

The behavior of Textile formatter can be changed with the following patch, but I think it is not easy to change the behavior of Markdown formatter because is done in [Redcarpet gem](https://github.com/vmg/redcarpet).

One solution would be to fix it in Markdown using your patch and create an issue with the Redcarpet project. Transparent code formatting is the more sensible behavior. If they want to keep the spaces for aesthetical reasons, then preserving tabs should be an option, whereas inconsistent behavior between formatters shall be shunned like the plague.

Also available in: Atom PDF