Method: ApplicationHelper#format_activity_description
- Defined in:
- app/helpers/application_helper.rb
#format_activity_description(text) ⇒ Object
416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'app/helpers/application_helper.rb', line 416 def format_activity_description(text) h( # Limit input to avoid regex performance issues text.to_s.slice(0, 10240) # Abbreviate consecutive quoted lines as '> ...', keeping the first line .gsub(%r{(^>.*?(?:\r?\n))(?:>.*?(?:\r?\n)+)+}m, "\\1> ...\n") # Remove all content following the first <pre> or <code> tag .sub(%r{[\r\n]*<(pre|code)>.*$}m, '') # Truncate the description to a specified length and append '...' .truncate(240) ).gsub(/[\r\n]+/, "<br>").html_safe end |