Browse Source

Better markdown output, for linuxfr

rails5
echarp 5 years ago
parent
commit
22e4cef45a
  1. 12
      app/helpers/events_helper.rb
  2. 9
      test/helpers/events_helper_test.rb

12
app/helpers/events_helper.rb

@ -63,12 +63,10 @@ module EventsHelper
tags: %w[p br h1 h2 h3 h4 table tr th td ul ol li a strong
b em i sub sup],
attributes: %w[href]
result = Kramdown::Document.new(desc, input: :html, line_width: line_width)
.to_kramdown
# Remove extraneous line feeds
return if result.nil? || result.blank?
result.gsub(/\n\n+/, '
').gsub(/\\([\"'])/, '\1')
Kramdown::Document.new(desc, input: :html, line_width: line_width)
.to_kramdown
.remove(/ +$/) # Remove extraneous line feeds
.gsub(/\\([\"'])/, '\1') # Remove slash before quotes
.gsub(/(\n\n)\n+/, '\1') # Fewer line feeds
end
end

9
test/helpers/events_helper_test.rb

@ -1,4 +1,13 @@
require 'test_helper'
# Test some event helper methods
class EventsHelperTest < ActionView::TestCase
test 'Markdown with empty content' do
assert_equal '', to_markdown('')
assert_equal '', to_markdown(' ')
assert_equal "'", to_markdown("\'")
assert_equal '', to_markdown('
')
end
end

Loading…
Cancel
Save