1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-01-31 11:37:14 +00:00

Append two spaces to lines when importing an email on CommonMark with hardbreaks disabled (#32424).

Patch by Jens Krämer.

git-svn-id: http://svn.redmine.org/redmine/trunk@21228 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Marius Balteanu 2021-10-03 19:20:04 +00:00
parent 09618a274b
commit 715ffcda43
4 changed files with 35 additions and 2 deletions

View File

@ -636,6 +636,9 @@ class MailHandler < ActionMailer::Base
unless delimiters.empty?
regex = Regexp.new("^(\\p{Space}|>)*(#{ Regexp.union(delimiters) })\\p{Space}*[\\r\\n].*", Regexp::MULTILINE)
if Setting.text_formatting == "common_mark" && Redmine::Configuration['common_mark_enable_hardbreaks'] == false
body = Redmine::WikiFormatting::CommonMark::AppendSpacesToLines.call(body)
end
body = body.gsub(regex, '')
end
body.strip

View File

@ -22,7 +22,7 @@
<p><%= setting_select :text_formatting, Redmine::WikiFormatting.formats_for_select, :blank => :label_none %>
<span id="common_mark_info" class="<%= "hidden" unless Setting.text_formatting == "common_mark" %>">
<label class="block">
<%= check_box_tag(nil, '', Redmine::Configuration['common_mark_enable_hardbreaks'] === true, disabled: true) %>
<%= check_box_tag(nil, '', Redmine::Configuration['common_mark_enable_hardbreaks'] == true, disabled: true) %>
Hardbreaks
</label>
<em class="info">

View File

@ -0,0 +1,30 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2021 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module Redmine
module WikiFormatting
module CommonMark
class AppendSpacesToLines
def self.call(string)
string&.gsub(/(?<! |\\)(\r?\n)/, " \\1")
end
end
end
end
end

View File

@ -46,7 +46,7 @@ module Redmine
],
}.freeze
if Redmine::Configuration['common_mark_enable_hardbreaks'] === true
if Redmine::Configuration['common_mark_enable_hardbreaks'] == true
PIPELINE_CONFIG[:commonmarker_render_options].push(:HARDBREAKS)
end
PIPELINE_CONFIG[:commonmarker_render_options].freeze