From 8b4263b2e270778dbcc2c6c559ffac1d6ddaf418 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Tue, 27 Jul 2021 02:25:27 +0300 Subject: [PATCH] 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..a776aca76 100644 --- a/app/views/settings/_general.html.erb +++ b/app/views/settings/_general.html.erb @@ -19,7 +19,16 @@

<%= 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 %> + "> + + Hardbreaks: <%= Redmine::Configuration['common_mark_enable_hardbreaks'] === true ? l(:label_enabled) : l(:label_disabled) %>. + + + You can configure the behaviour in config/configuration.yml. Please restart the application after editing it. + + +

<%= setting_check_box :cache_formatted_text %>

@@ -32,3 +41,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("common_mark_info"); + + if (formatter == "common_mark") { + parent_block.classList.remove('hidden'); + } else { + parent_block.classList.add('hidden'); + } + }); +<% end %> diff --git a/config/configuration.yml.example b/config/configuration.yml.example index 8e350228e..e1dbb19c2 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -224,6 +224,13 @@ default: #avatar_server_url: https://www.gravatar.com # default #avatar_server_url: https://seccdn.libravatar.org + # Configure CommonMark hardbreaks behaviour + # + # allowed values: true, false + # true: treats regular line break (\n) as hardbreaks + # false: switches to default common mark where two or more spaces are required + # common_mark_enable_hardbreaks: true + # specific configuration options for production environment # that overrides the default ones production: diff --git a/config/locales/en.yml b/config/locales/en.yml index e72e1bf89..f4f0671b7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -893,6 +893,7 @@ en: label_copied_to: Copied to label_copied_from: Copied from label_stay_logged_in: Stay logged in + label_enabled: enabled label_disabled: disabled label_optional: optional label_show_completed_versions: Show completed versions diff --git a/lib/redmine/configuration.rb b/lib/redmine/configuration.rb index 883dc8497..aff2651bb 100644 --- a/lib/redmine/configuration.rb +++ b/lib/redmine/configuration.rb @@ -24,7 +24,8 @@ module Redmine @defaults = { 'avatar_server_url' => 'https://www.gravatar.com', 'email_delivery' => nil, - 'max_concurrent_ajax_uploads' => 2 + 'max_concurrent_ajax_uploads' => 2, + 'common_mark_enable_hardbreaks' => true } @config = nil diff --git a/lib/redmine/wiki_formatting/common_mark/formatter.rb b/lib/redmine/wiki_formatting/common_mark/formatter.rb index d0db8c9b8..3c2f3ad09 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 Redmine::Configuration['common_mark_enable_hardbreaks'] === true + PIPELINE_CONFIG[:commonmarker_render_options].push(:HARDBREAKS) + end + PIPELINE_CONFIG[:commonmarker_render_options].freeze + MarkdownPipeline = HTML::Pipeline.new [ MarkdownFilter, SanitizationFilter, -- 2.22.0