You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.8 KiB

  1. # frozen_string_literal: true
  2. module FormattingHelper
  3. def html_aware_format(text, local, options = {})
  4. HtmlAwareFormatter.new(text, local, options).to_s
  5. end
  6. def linkify(text, options = {})
  7. TextFormatter.new(text, options).to_s
  8. end
  9. def extract_status_plain_text(status)
  10. PlainTextFormatter.new(status.text, status.local?).to_s
  11. end
  12. module_function :extract_status_plain_text
  13. def status_content_format(status)
  14. html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []))
  15. end
  16. def rss_status_content_format(status)
  17. html = status_content_format(status)
  18. before_html = begin
  19. if status.spoiler_text?
  20. "<p><strong>#{I18n.t('rss.content_warning', locale: available_locale_or_nil(status.language) || I18n.default_locale)}</strong> #{h(status.spoiler_text)}</p><hr />"
  21. else
  22. ''
  23. end
  24. end.html_safe # rubocop:disable Rails/OutputSafety
  25. after_html = begin
  26. if status.preloadable_poll
  27. "<p>#{status.preloadable_poll.options.map { |o| "<input type=#{status.preloadable_poll.multiple? ? 'checkbox' : 'radio'} disabled /> #{h(o)}" }.join('<br />')}</p>"
  28. else
  29. ''
  30. end
  31. end.html_safe # rubocop:disable Rails/OutputSafety
  32. prerender_custom_emojis(
  33. safe_join([before_html, html, after_html]),
  34. status.emojis,
  35. style: 'width: 1.1em; height: 1.1em; object-fit: contain; vertical-align: middle; margin: -.2ex .15em .2ex'
  36. ).to_str
  37. end
  38. def account_bio_format(account)
  39. html_aware_format(account.note, account.local?)
  40. end
  41. def account_field_value_format(field, with_rel_me: true)
  42. html_aware_format(field.value, field.account.local?, with_rel_me: with_rel_me, with_domains: true, multiline: false)
  43. end
  44. end