Pre-truncate excerpt before running replacement regexes

Also fixes <ol> normalization which was previously a noop.
This commit is contained in:
Zacharias Dyna Knudsen
2026-03-23 09:24:17 +01:00
parent 743b60d393
commit 6c771584d7
2 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -3,9 +3,10 @@ module ExcerptHelper
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(/^\d+\.\s*(.*)$/m) { |m| m }
text = text.gsub(/^\s*(\d+\.)\s*(.*)$/m, '\1 \2')
text = text.gsub(/\s+/, " ").strip
text.truncate(length)
end
+2 -1
View File
@@ -11,7 +11,8 @@ class ExcerptHelperTest < ActionView::TestCase
end
test "ol" do
assert_excerpt("99. Hello world", "99. Hello world")
assert_excerpt("99. Hello world", "99. Hello world")
assert_excerpt("99. Hello world", " 99. Hello world")
end
test "large spaces" do