Attempt to improve the markdown digest
This commit is contained in:
parent
2d9107997f
commit
1aa7aa936b
8
app/helpers/digest_helper.rb
Normal file
8
app/helpers/digest_helper.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Helper for the digest/markdown views
|
||||||
|
module DigestHelper
|
||||||
|
# Important mechanism, to ensure the digest will not have the same footnote
|
||||||
|
# link multiple times
|
||||||
|
def renumber_footnotes(id, description)
|
||||||
|
description.gsub(/\[(\d)*\]/, "[#{id}_\\1]")
|
||||||
|
end
|
||||||
|
end
|
@ -56,6 +56,8 @@ module EventsHelper
|
|||||||
item.class.human_attribute_name(label).rjust(12) + " #{value}"
|
item.class.human_attribute_name(label).rjust(12) + " #{value}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Using kramdown, let's parse the html and render it as markdown text
|
||||||
|
# No idea why, but also needs to remove extraneous quote encoding :(
|
||||||
def to_markdown(description, line_width = -1)
|
def to_markdown(description, line_width = -1)
|
||||||
desc = sanitize description,
|
desc = sanitize description,
|
||||||
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
|
||||||
@ -64,8 +66,9 @@ module EventsHelper
|
|||||||
result = Kramdown::Document.new(desc, input: :html, line_width: line_width)
|
result = Kramdown::Document.new(desc, input: :html, line_width: line_width)
|
||||||
.to_kramdown
|
.to_kramdown
|
||||||
# Remove extraneous line feeds
|
# Remove extraneous line feeds
|
||||||
|
return if result.nil? || result.blank?
|
||||||
result.gsub(/\n\n+/, '
|
result.gsub(/\n\n+/, '
|
||||||
|
|
||||||
').tr('\\', '').html_safe
|
').gsub(/(\w)\\'/, '\1\'')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
- @events.sort_by(&:start_time).each do |event|
|
- @events.sort_by(&:start_time).each do |event|
|
||||||
[#{event.region.region.try(:code) || event.region.try(:code)} #{event.city}] [#{event.title}](#{event_url event}) - #{display_date event}
|
[#{event.region.region.try(:code) || event.region.try(:code)} #{event.city}] [#{event.title}](#{event_url event}) - #{display_date event}
|
||||||
\-----
|
\-----
|
||||||
= to_markdown event.description, -1
|
= renumber_footnotes event.id, to_markdown(event.description)
|
||||||
\
|
\
|
||||||
* #{[event.place_name, event.full_address].compact.join ', '}
|
* #{[event.place_name, event.full_address].compact.join ', '}
|
||||||
- if event.url.present?
|
- if event.url.present?
|
||||||
|
@ -15,5 +15,5 @@
|
|||||||
= display_attr @event, :repeat
|
= display_attr @event, :repeat
|
||||||
= display_attr @event, :rule, t(@event.rule, scope: 'activerecord.attributes.event.rule_values')
|
= display_attr @event, :rule, t(@event.rule, scope: 'activerecord.attributes.event.rule_values')
|
||||||
\
|
\
|
||||||
= to_markdown @event.description, 78
|
= raw to_markdown @event.description, 78
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
Loading…
Reference in New Issue
Block a user