mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-23 09:58:07 +01:00
cefa526c6d
* Refactor formatter * Move custom emoji pre-rendering logic to view helpers * Move more methods out of Formatter * Fix code style issues * Remove Formatter * Add inline poll options to RSS feeds * Remove unused helper method * Fix code style issues * Various fixes and improvements * Fix test
38 lines
677 B
Ruby
38 lines
677 B
Ruby
# frozen_string_literal: true
|
|
|
|
class HtmlAwareFormatter
|
|
attr_reader :text, :local, :options
|
|
|
|
alias local? local
|
|
|
|
# @param [String] text
|
|
# @param [Boolean] local
|
|
# @param [Hash] options
|
|
def initialize(text, local, options = {})
|
|
@text = text
|
|
@local = local
|
|
@options = options
|
|
end
|
|
|
|
def to_s
|
|
return ''.html_safe if text.blank?
|
|
|
|
if local?
|
|
linkify
|
|
else
|
|
reformat.html_safe # rubocop:disable Rails/OutputSafety
|
|
end
|
|
rescue ArgumentError
|
|
''.html_safe
|
|
end
|
|
|
|
private
|
|
|
|
def reformat
|
|
Sanitize.fragment(text, Sanitize::Config::MASTODON_STRICT)
|
|
end
|
|
|
|
def linkify
|
|
TextFormatter.new(text, options).to_s
|
|
end
|
|
end
|