Better markdown output, for linuxfr

This commit is contained in:
echarp 2017-06-10 14:28:10 +02:00
parent 69bfd4ffc4
commit 22e4cef45a
2 changed files with 14 additions and 7 deletions

View File

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

View File

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