From 24ff28b64ab036c82b5f5a7ec6a380663e26c6c3 Mon Sep 17 00:00:00 2001
From: echarp <manu@echarp.org>
Date: Sun, 3 Mar 2019 16:38:45 +0000
Subject: [PATCH] b and i tags also have their eventual inner spaces better
 managed

---
 app/helpers/events_helper.rb       | 7 ++++---
 test/helpers/events_helper_test.rb | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb
index 74c478685..97b26b90d 100644
--- a/app/helpers/events_helper.rb
+++ b/app/helpers/events_helper.rb
@@ -66,6 +66,7 @@ module EventsHelper
     Kramdown::Document.new(spaces(desc), input: :html, line_width: line_width)
                       .to_kramdown
                       .gsub(/\\([\"'])/, '\1') # Remove slash before quotes
+                      .remove(/[[:blank:]]+$/) # Remove extraneous spaces
                       .remove(/{::}/) # Markdown artefact
   end
 
@@ -73,8 +74,8 @@ module EventsHelper
 
   # Cleaner html elements, to correct things like <em> test</em>
   def spaces(desc)
-    desc.gsub(/<(strong|em)> /, ' <\1>')
-        .gsub(%r{ </(strong|em)>}, '</\1> ')
-        .gsub(/ ([,.])/, '\1')
+    desc.gsub(/<(strong|em|b|i)> /, ' <\1>')
+        .gsub(%r{ </(strong|em|b|i)>}, '</\1> ')
+        .gsub(/[[:space:]]([,.])/, '\1')
   end
 end
diff --git a/test/helpers/events_helper_test.rb b/test/helpers/events_helper_test.rb
index 53b0c4f35..bfd42e928 100644
--- a/test/helpers/events_helper_test.rb
+++ b/test/helpers/events_helper_test.rb
@@ -16,5 +16,6 @@ class EventsHelperTest < ActionView::TestCase
     assert_equal '**h**,', to_markdown('<strong>h </strong>,')
     assert_equal '*ho***h**,', to_markdown('<em>ho</em><strong>h </strong>,')
     assert_equal '*ho* **h**,', to_markdown('<em>ho</em><strong> h</strong>,')
+    assert_equal '*ho* **h**,', to_markdown('<i>ho</i><b> h</b>,')
   end
 end
-- 
GitLab