diff --git a/app/helpers/excerpt_helper.rb b/app/helpers/excerpt_helper.rb index 9ae0d3274..b48986c26 100644 --- a/app/helpers/excerpt_helper.rb +++ b/app/helpers/excerpt_helper.rb @@ -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) diff --git a/test/helpers/excerpt_helper_test.rb b/test/helpers/excerpt_helper_test.rb index b3dff7a0b..ef685680b 100644 --- a/test/helpers/excerpt_helper_test.rb +++ b/test/helpers/excerpt_helper_test.rb @@ -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