Event's description has their eventual empty paragraphs removed.
Plus remove a strange {::} markdown artifact
This commit is contained in:
parent
995efe9034
commit
803511cde2
@ -63,10 +63,18 @@ 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]
|
||||||
Kramdown::Document.new(desc, input: :html, line_width: line_width)
|
Kramdown::Document.new(spaces(desc), input: :html, line_width: line_width)
|
||||||
.to_kramdown
|
.to_kramdown
|
||||||
.remove(/ +$/) # Remove extraneous line feeds
|
|
||||||
.gsub(/\\([\"'])/, '\1') # Remove slash before quotes
|
.gsub(/\\([\"'])/, '\1') # Remove slash before quotes
|
||||||
.gsub(/(\n\n)\n+/, '\1') # Fewer line feeds
|
.remove(/{::}/) # Markdown artefact
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# 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')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -95,6 +95,11 @@ class Event < ApplicationRecord
|
|||||||
tag_list.map { |tag| "##{tag.tr('-', '_').camelize :lower}" }
|
tag_list.map { |tag| "##{tag.tr('-', '_').camelize :lower}" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def description
|
||||||
|
# Remove empty paragraphs, which are added by tinymce
|
||||||
|
self[:description]&.remove '<p> </p>'
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#{start_time.to_date} #{city}: #{title} #{hashtags.join(' ')}"
|
"#{start_time.to_date} #{city}: #{title} #{hashtags.join(' ')}"
|
||||||
end
|
end
|
||||||
|
@ -9,4 +9,12 @@ class EventsHelperTest < ActionView::TestCase
|
|||||||
assert_equal '', to_markdown('
|
assert_equal '', to_markdown('
|
||||||
')
|
')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'HTML elements with a space inside' do
|
||||||
|
assert_equal '**hello world**', to_markdown('<strong>hello world </strong>')
|
||||||
|
assert_equal '**h**,', to_markdown('<strong> h</strong>,')
|
||||||
|
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>,')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user