Sha256: c94e86fdae835dc2644eeac14a1ca32958582221b35b9208e661d1361956c1bb

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require "refinements/array"
require "sanitize"

module Milestoner
  # A custom HTML sanitizer.
  class Sanitizer
    using Refinements::Array

    def initialize defaults: Sanitize::Config::BASIC, client: Sanitize
      @defaults = defaults
      @client = client
    end

    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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
milestoner-18.11.0 lib/milestoner/sanitizer.rb
milestoner-18.10.0 lib/milestoner/sanitizer.rb
milestoner-18.9.0 lib/milestoner/sanitizer.rb
milestoner-18.8.0 lib/milestoner/sanitizer.rb
milestoner-18.7.0 lib/milestoner/sanitizer.rb
milestoner-18.6.0 lib/milestoner/sanitizer.rb
milestoner-18.5.0 lib/milestoner/sanitizer.rb