Make ExcerptHelper work for String inputs

This commit is contained in:
Mike Dalessio
2025-08-11 17:38:24 -04:00
parent d2a0196fe2
commit d2da1dcc06
2 changed files with 3 additions and 2 deletions
+2 -2
View File
@@ -2,9 +2,9 @@ module ExcerptHelper
def format_excerpt(content, length: 200)
return "" if content.blank?
text = content.to_plain_text
text = content.respond_to?(:to_plain_text) ? content.to_plain_text : content.to_s
text = text.gsub(/^>\s*(.*)$/m, '> \1')
text = text.gsub(/^[-*]\s*(.*)$/m, '• \1')
text = text.gsub(/^\s*[-+]\s*(.*)$/m, '• \1')
text = text.gsub(/^\d+\.\s*(.*)$/m) { |m| m }
text = text.gsub(/\s+/, " ").strip
text.truncate(length)
+1
View File
@@ -26,5 +26,6 @@ class ExcerptHelperTest < ActionView::TestCase
private
def assert_excerpt(expected, content, ...)
assert_equal expected, format_excerpt(ActionText::Content.new(content), ...), "Excerpt of Action Text Content does not match"
assert_equal expected, format_excerpt(content, ...), "Excerpt of String does not match"
end
end