commit 9abd5972c4e9552833d8cc75e5f26a5a94e6829e Author: Marius BALTEANU Date: Tue Jul 27 02:25:27 2021 +0300 Add setting to controll the hardbreaks behaviour from admin (#32424). diff --git a/app/views/settings/_general.html.erb b/app/views/settings/_general.html.erb index 23abdb3f5..a51930878 100644 --- a/app/views/settings/_general.html.erb +++ b/app/views/settings/_general.html.erb @@ -19,8 +19,12 @@

<%= setting_select :protocol, [['HTTP', 'http'], ['HTTPS', 'https']] %>

-

<%= setting_select :text_formatting, Redmine::WikiFormatting.formats_for_select, :blank => :label_none %>

- +

<%= setting_select :text_formatting, Redmine::WikiFormatting.formats_for_select, :blank => :label_none %> + +

<%= setting_check_box :cache_formatted_text %>

<%= setting_select :wiki_compression, [['Gzip', 'gzip']], :blank => :label_none %>

@@ -32,3 +36,16 @@ <%= submit_tag l(:button_save) %> <% end %> + +<%= javascript_tag do %> + $('#settings_text_formatting').on('change', function(e){ + const formatter = e.target.value; + const parent_block = document.getElementById("settings_text_formatting_common_mark_hardbreaks").parentElement; + + if (formatter == "common_mark") { + parent_block.classList.remove('hidden'); + } else { + parent_block.classList.add('hidden'); + } + }); +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index e72e1bf89..ee6379b14 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -511,6 +511,7 @@ en: setting_project_list_defaults: Projects list defaults setting_twofa: Two-factor authentication setting_default_issue_query: Default Query + setting_text_formatting_common_mark_hardbreaks: "Use regular line breaks (\\n) as hardbreaks" permission_add_project: Create project permission_add_subprojects: Create subprojects diff --git a/config/settings.yml b/config/settings.yml index 7960a3f29..0248868bc 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -98,6 +98,8 @@ plain_text_mail: default: 0 text_formatting: default: textile +text_formatting_common_mark_hardbreaks: + default: 1 cache_formatted_text: default: 0 wiki_compression: diff --git a/lib/redmine/wiki_formatting/common_mark/formatter.rb b/lib/redmine/wiki_formatting/common_mark/formatter.rb index d0db8c9b8..cd0c8ba30 100644 --- a/lib/redmine/wiki_formatting/common_mark/formatter.rb +++ b/lib/redmine/wiki_formatting/common_mark/formatter.rb @@ -43,9 +43,14 @@ module Redmine # https://github.com/gjtorikian/commonmarker#render-options commonmarker_render_options: [ :UNSAFE - ].freeze, + ], }.freeze + if Setting.text_formatting_common_mark_hardbreaks? + PIPELINE_CONFIG[:commonmarker_render_options].push(:HARDBREAKS) + PIPELINE_CONFIG[:commonmarker_render_options].freeze + end + MarkdownPipeline = HTML::Pipeline.new [ MarkdownFilter, SanitizationFilter, diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index e117bc1d0..0b165b447 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -844,6 +844,10 @@ label.block { float: none; } +.tabular label.block.hidden { + display: none; +} + .tabular label.inline{ font-weight: normal; float:none;