b and i tags also have their eventual inner spaces better managed

This commit is contained in:
echarp 2019-03-03 16:38:45 +00:00
parent 2cc8012731
commit 24ff28b64a
2 changed files with 5 additions and 3 deletions

View File

@ -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

View File

@ -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