Feature #32528

Make languages in Highlighted code button in toolbar customizable

Added by Mizuki ISHIKAWA about 1 month ago. Updated 5 days ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Text formatting
Target version:4.2.0
Resolution:Fixed

Description

Languages often used in code highlights differ from person to person.
I think it would be convenient if the language set in the user setting is given as a candidate.

example2.png (43.5 KB) Mizuki ISHIKAWA, 2019-11-29 03:24

example1.png (137 KB) Mizuki ISHIKAWA, 2019-11-29 03:24

feature-32528.patch Magnifier (6.85 KB) Mizuki ISHIKAWA, 2019-11-29 03:24

feature-32528-2.patch Magnifier (6.82 KB) Mizuki ISHIKAWA, 2019-12-04 01:00

feature-32528-3.patch Magnifier (6.75 KB) Go MAEDA, 2019-12-15 09:10


Related issues

Related to Redmine - Feature #14937: Code highlighting toolbar button Closed

Associated revisions

Revision 19429
Added by Go MAEDA 5 days ago

Make languages in Highlighted code button in toolbar customizable (#32528).

Patch by Mizuki ISHIKAWA.

Revision 19430
Added by Go MAEDA 5 days ago

Update locales (#32528).

History

#1 Updated by Mizuki ISHIKAWA about 1 month ago

I attached a patch.
After applying this patch to the development environment, you need to restart Redmine.

  • user setting
  • wiki toolbar

#2 Updated by Go MAEDA about 1 month ago

Thank you for writing the patch. But I think that filling the textarea in "My account" with the default languages is better. The reason is that it makes easier to customize the default values.

Suppose that you are about to add "soncole" to the menu. You can see the current languages list in the textarea of "My account" page as a placeholder. But the placeholder is cleared when you start typing and you have to manage to remember the value that was displayed just before. The small frustration can be resolved by applying the following patch on top of your patch.

diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index 63c6a9151..26f1efdcf 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -100,7 +100,9 @@ class UserPreference < ActiveRecord::Base
   def history_default_tab; self[:history_default_tab]; end
   def history_default_tab=(value); self[:history_default_tab]=value; end

-  def code_highlighting_languages; self[:code_highlighting_languages]; end
+  def code_highlighting_languages
+    self[:code_highlighting_languages].presence || DEFAULT_CODE_HIGHLIGHTING_LANGUAGES.join(',')
+  end
   def code_highlighting_languages=(value)
     languages = value.to_s.gsub(' ', '').split(',').select{|lang| Redmine::SyntaxHighlighting.language_supported?(lang) }.compact
     self[:code_highlighting_languages] = languages.join(',')
diff --git a/app/views/users/_preferences.html.erb b/app/views/users/_preferences.html.erb
index 2daa7cef4..c344ab4d8 100644
--- a/app/views/users/_preferences.html.erb
+++ b/app/views/users/_preferences.html.erb
@@ -6,5 +6,5 @@
 <p><%= pref_fields.select :textarea_font, textarea_font_options %></p>
 <p><%= pref_fields.text_field :recently_used_projects, :size => 2 %></p>
 <p><%= pref_fields.select :history_default_tab, history_default_tab_options %></p>
-<p><%= pref_fields.text_area :code_highlighting_languages, :placeholder => UserPreference::DEFAULT_CODE_HIGHLIGHTING_LANGUAGES.join(','), :rows => 4 %></p>
+<p><%= pref_fields.text_area :code_highlighting_languages, :rows => 4 %></p>
 <% end %>

#3 Updated by Mizuki ISHIKAWA about 1 month ago

Thank you for your feedback.
I updated the patch.

#4 Updated by Go MAEDA about 1 month ago

  • Category changed from Wiki to Text formatting
  • Target version set to Candidate for next major release

#5 Updated by Go MAEDA about 1 month ago

#6 Updated by Go MAEDA about 1 month ago

This is a nice improvement.

When the code highlight button was introduced in Redmine 3.3, the code highlighter supported only about 20 languages and the button covered almost all supported languages. But now, the code highlighter in Redmine 4.0 supports over 100 languages. It is no longer possible to put all supported languages in the toolbar button.

As Mizuki mentioned, languages that should be in the toolbar is different per user. For example, I don't use most default options such as go, java, and php but often use "console".

Allowing users to customize the options in the toolbar button solves problems above. I think this feature is useful for all users who use code highlighting.

#7 Updated by Go MAEDA about 1 month ago

I slightly updated the patch (changed the preference name from 'code_highlighting_languages' to 'toolbar_language_options').

Setting the target version to 4.2.0.

#8 Updated by Go MAEDA 5 days ago

  • Subject changed from Customize language options for highlight tag insertion in the Wiki toolbar to Make languages in Highlighted code button in toolbar customizable
  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch. Thank you for improving Redmine.

Also available in: Atom PDF