Skip to content
Extraits de code Groupes Projets
Valider 1aa7aa93 rédigé par echarp's avatar echarp
Parcourir les fichiers

Attempt to improve the markdown digest

parent 2d910799
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
# 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
==============================================================================
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter