Attempt to improve the markdown digest

rails5
echarp 6 years ago
parent 2d9107997f
commit 1aa7aa936b
  1. 8
      app/helpers/digest_helper.rb
  2. 5
      app/helpers/events_helper.rb
  3. 2
      app/views/digests/markdown.html.haml
  4. 2
      app/views/events/show.text.haml

@ -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}"
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)
desc = sanitize description,
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)
.to_kramdown
# Remove extraneous line feeds
return if result.nil? || result.blank?
result.gsub(/\n\n+/, '
').tr('\\', '').html_safe
').gsub(/(\w)\\'/, '\1\'')
end
end

@ -8,7 +8,7 @@
- @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}
\-----
= to_markdown event.description, -1
= renumber_footnotes event.id, to_markdown(event.description)
\
* #{[event.place_name, event.full_address].compact.join ', '}
- if event.url.present?

@ -15,5 +15,5 @@
= display_attr @event, :repeat
= 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…
Cancel
Save