Feature #4267

<code> block improvements

Added by Aleksej Lebedev almost 10 years ago. Updated about 7 years ago.

Status:NewStart date:2009-11-23
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Text formatting
Target version:-
Resolution:

Description

I think it would be useful to implement the following features1 for code block

Source code:

&lt;pre&gt;&lt;code class="ruby"&gt;
# The Greeter class
class Greeter
  def initialize(name)
    @name = name.capitalize
  end

  def salute
    puts "Hello #{@name}!" 
  end
end
&lt;/code&gt;&lt;/pre&gt;

Result:

# The Greeter class
class Greeter
  def initialize(name)
    @name = name.capitalize
  end

  def salute
    puts "Hello #{@name}!" 
  end
end

:line_numbers2

&lt;code class="ruby" lineNumbers="yes"&gt;.....&lt;/code&gt;
&lt;code class="ruby" lineNumbers="no"&gt;.....&lt;/code&gt;

:line_number_start2

&lt;code class="ruby" start="50"&gt;.....&lt;/code&gt;

:bold_every2

&lt;code class="ruby" every="2"&gt;.....&lt;/code&gt;

:highlight_lines2

&lt;code class="ruby" highlight="1,3,5,7"&gt;.....&lt;/code&gt;

title

&lt;code class="ruby" title="/path/to/file.rb"&gt;.....&lt;/code&gt;


1 This standard features in CodeRay, but unfortunately not supported in Redmine :(

2 CodeRay HTML Encoder options

Redmine_code_lineNumbers_no.png (5.51 KB) Aleksej Lebedev, 2009-11-23 13:46

Redmine_code_start_50.png (6.39 KB) Aleksej Lebedev, 2009-11-23 13:46

Redmine_every_2.png (6.11 KB) Aleksej Lebedev, 2009-11-23 13:46

Redmine_highlight_1_3_5_7.png (6.22 KB) Aleksej Lebedev, 2009-11-23 13:46

Redmine_title.png (5.32 KB) Aleksej Lebedev, 2009-11-23 13:46


Related issues

Related to Redmine - Feature #3382: Ability to select only source code without line numbers New 2009-05-18

History

#1 Updated by Mischa The Evil almost 10 years ago

+10 from me on this one. I actually still had to file this issue myself... Thanks for doing it for me :)

These options really would make syntax-highlighting more useable IMHO.

#2 Updated by Kornelius Kalnbach over 9 years ago

It seems to me that :line_number_start and highlight_lines are most useful. We should focus on them, to keep the highlighter plugin API simple, and ensure that other highlighters can adapt.

#3 Updated by William Baum over 9 years ago

For me, the inability to cut and paste code without the line numbers is a deal-breaker. Furthermore, without representing file line numbers, I don't see how they add value. While the CODE blocks are prettier, the plain PRE blocks are better for exchanging code snippets, simply due to the line numbers.

In terms of usefulness and ease of implementation, the CodeRay features I'd like to see supported are:

  1. Suppress the line numbers
    :line_numbers => nil
    
  2. Use the table method:
    :line_numbers => :table
    
  3. Use actual file line numbers:
    :line_number_start
    

I did experiment with changing the line numbering method in lib/redmine/syntax_highlighting.rb.

nil works fine and does suppress the line numbers. :table will require some changes to the style declarations to get working properly, but would fix the clipboard issues. The samples on the CodeRay site that cut and paste well seem to be using the :table method.

#4 Updated by Eric Thomas over 9 years ago

William Baum wrote:

For me, the inability to cut and paste code without the line numbers is a deal-breaker. Furthermore, without representing file line numbers, I don't see how they add value. While the CODE blocks are prettier, the plain PRE blocks are better for exchanging code snippets, simply due to the line numbers.

In terms of usefulness and ease of implementation, the CodeRay features I'd like to see supported are:

  1. Suppress the line numbers
    [...]
  2. Use the table method:
    [...]
  3. Use actual file line numbers:
    [...]

I did experiment with changing the line numbering method in lib/redmine/syntax_highlighting.rb.

nil works fine and does suppress the line numbers. :table will require some changes to the style declarations to get working properly, but would fix the clipboard issues. The samples on the CodeRay site that cut and paste well seem to be using the :table method.

William, if you get a chance please see my patch at #3382. Thanks.

#5 Updated by Ling Li over 8 years ago

+1

I like William Baum's suggestion in note#3 a lot! Would this be put into some planned version?

William Baum wrote:

For me, the inability to cut and paste code without the line numbers is a deal-breaker.

Strongly agree!

#6 Updated by Anthony Gerrard over 8 years ago

Generally +1

For me, the inability to cut and paste code without the line numbers is a deal-breaker.

+10 on this

Also available in: Atom PDF