Files
fizzy/app/helpers/excerpt_helper.rb
T
Zacharias Dyna Knudsen 6c771584d7 Pre-truncate excerpt before running replacement regexes
Also fixes <ol> normalization which was previously a noop.
2026-03-23 10:21:35 +01:00

14 lines
442 B
Ruby

module ExcerptHelper
def format_excerpt(content, length: 200)
return "" if content.blank?
text = content.respond_to?(:to_plain_text) ? content.to_plain_text : content.to_s
text = text.first(length * 2)
text = text.gsub(/^>\s*(.*)$/m, '> \1')
text = text.gsub(/^\s*[-+]\s*(.*)$/m, '• \1')
text = text.gsub(/^\s*(\d+\.)\s*(.*)$/m, '\1 \2')
text = text.gsub(/\s+/, " ").strip
text.truncate(length)
end
end