From 36b2d5b4d025291ac8ccc90ca662ccb1337aa9b4 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Sat, 4 Sep 2021 14:20:28 +0300 Subject: [PATCH] Add setting in admin to control the hardbreaks behaviour for CommonMark (#32424). diff --git a/app/views/settings/_general.html.erb b/app/views/settings/_general.html.erb index 23abdb3f5..937b42322 100644 --- a/app/views/settings/_general.html.erb +++ b/app/views/settings/_general.html.erb @@ -19,7 +19,13 @@

<%= 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 %>

@@ -32,3 +38,15 @@ <%= submit_tag l(:button_save) %> <% end %> + +<%= javascript_tag do %> + $('#settings_text_formatting').on('change', function(e){ + const formatter = e.target.value; + const settings = document.getElementById("common_mark_settings"); + if (formatter == "common_mark") { + settings.classList.remove('hidden'); + } else { + settings.classList.add('hidden'); + } + }); +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 952138bf4..ac759d250 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -510,6 +510,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 64209bdfd..f36a72236 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -96,6 +96,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 6a9c95c8e..44e4de8f0 100644 --- a/lib/redmine/wiki_formatting/common_mark/formatter.rb +++ b/lib/redmine/wiki_formatting/common_mark/formatter.rb @@ -42,9 +42,8 @@ module Redmine # https://github.com/gjtorikian/commonmarker#render-options commonmarker_render_options: [ - :HARDBREAKS, :UNSAFE - ].freeze, + ], }.freeze MarkdownPipeline = HTML::Pipeline.new [ @@ -57,6 +56,12 @@ module Redmine class Formatter < Redmine::WikiFormatting::Markdown::Formatter def to_html(*args) + if Setting.text_formatting_common_mark_hardbreaks? + PIPELINE_CONFIG[:commonmarker_render_options].push(:HARDBREAKS) unless PIPELINE_CONFIG[:commonmarker_render_options].include?(:HARDBREAKS) + else + PIPELINE_CONFIG[:commonmarker_render_options].delete(:HARDBREAKS) if PIPELINE_CONFIG[:commonmarker_render_options].include?(:HARDBREAKS) + end + result = MarkdownPipeline.call @text result[:output].to_s end diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 9f6b4dc3d..0dff30825 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -849,6 +849,10 @@ label.block { float: none; } +.tabular label.block.hidden { + display: none; +} + .tabular label.inline{ font-weight: normal; float:none; -- 2.22.0