class Milestoner::Sanitizer

A custom HTML sanitizer.

Public Class Methods

new(defaults: Sanitize::Config::BASIC, client: Sanitize) click to toggle source
# File lib/milestoner/sanitizer.rb, line 11
def initialize defaults: Sanitize::Config::BASIC, client: Sanitize
  @defaults = defaults
  @client = client
end

Public Instance Methods

attributes() click to toggle source
# File lib/milestoner/sanitizer.rb, line 28
def attributes
  defaults[:attributes].merge(
    all: %w[class id],
    "a" => %w[href title],
    "audio" => %w[autoplay controls controlslist crossorigin loop muted preload src],
    "details" => %w[name open],
    "img" => %w[alt height loading src width],
    "source" => %w[type src srcset sizes media height width],
    "video" => %w[controls height poster src width]
  )
end
call(content) click to toggle source
# File lib/milestoner/sanitizer.rb, line 16
    def call(content) = client.fragment content, configuration

    private

    attr_reader :defaults, :client

    def configuration = client::Config.merge(defaults, elements:, attributes:)

    def elements
      defaults[:elements].including "audio", "details", "img", "source", "span", "summary", "video"
    end

    def attributes
      defaults[:attributes].merge(
        all: %w[class id],
        "a" => %w[href title],
        "audio" => %w[autoplay controls controlslist crossorigin loop muted preload src],
        "details" => %w[name open],
        "img" => %w[alt height loading src width],
        "source" => %w[type src srcset sizes media height width],
        "video" => %w[controls height poster src width]
      )
    end
  end
end
configuration(= client::Config.merge(defaults, elements:, attributes:)) click to toggle source
# File lib/milestoner/sanitizer.rb, line 22
  def configuration = client::Config.merge(defaults, elements:, attributes:)

  def elements
    defaults[:elements].including "audio", "details", "img", "source", "span", "summary", "video"
  end

  def attributes
    defaults[:attributes].merge(
      all: %w[class id],
      "a" => %w[href title],
      "audio" => %w[autoplay controls controlslist crossorigin loop muted preload src],
      "details" => %w[name open],
      "img" => %w[alt height loading src width],
      "source" => %w[type src srcset sizes media height width],
      "video" => %w[controls height poster src width]
    )
  end
end
elements() click to toggle source
# File lib/milestoner/sanitizer.rb, line 24
def elements
  defaults[:elements].including "audio", "details", "img", "source", "span", "summary", "video"
end