Browse Source

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

remotes/origin/master
echarp 3 years ago
parent
commit
24ff28b64a
  1. 7
      app/helpers/events_helper.rb
  2. 1
      test/helpers/events_helper_test.rb

7
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

1
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

Loading…
Cancel
Save