From 715ffcda434b8ad224127d008f3376adfbcc2c85 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 3 Oct 2021 19:20:04 +0000 Subject: [PATCH] Append two spaces to lines when importing an email on CommonMark with hardbreaks disabled (#32424). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@21228 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mail_handler.rb | 3 ++ app/views/settings/_general.html.erb | 2 +- .../common_mark/append_spaces_to_lines.rb | 30 +++++++++++++++++++ .../wiki_formatting/common_mark/formatter.rb | 2 +- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 lib/redmine/wiki_formatting/common_mark/append_spaces_to_lines.rb diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index fd2e25fb5..4f9c73136 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -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 diff --git a/app/views/settings/_general.html.erb b/app/views/settings/_general.html.erb index b8d82486a..043067f18 100644 --- a/app/views/settings/_general.html.erb +++ b/app/views/settings/_general.html.erb @@ -22,7 +22,7 @@

<%= setting_select :text_formatting, Redmine::WikiFormatting.formats_for_select, :blank => :label_none %> "> diff --git a/lib/redmine/wiki_formatting/common_mark/append_spaces_to_lines.rb b/lib/redmine/wiki_formatting/common_mark/append_spaces_to_lines.rb new file mode 100644 index 000000000..73c5a4177 --- /dev/null +++ b/lib/redmine/wiki_formatting/common_mark/append_spaces_to_lines.rb @@ -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(/(?