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

View File

@ -1,4 +1,13 @@
require 'test_helper' require 'test_helper'
# Test some event helper methods
class EventsHelperTest < ActionView::TestCase 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 end