Sha256: 3f85f097bb000c2fcea846cdd8e33f2a63e322adf7b5510511bf49c18a247d7d

Contents?: true

Size: 705 Bytes

Versions: 2

Compression:

Stored size: 705 Bytes

Contents

module Slodown
  class EmbedTransformer
    ALLOWED_DOMAINS = %w[youtube.com soundcloud.com vimeo.com]

    def self.call(env)
      node      = env[:node]
      node_name = env[:node_name]

      return if env[:is_whitelisted] || !env[:node].element?
      return unless %w[iframe embed].include? env[:node_name]

      uri = URI(env[:node]['src'])
      domains = ALLOWED_DOMAINS.map { |d| Regexp.escape(d) }.join("|")
      return unless uri.host =~ /^(.+\.)?(#{domains})/

      Sanitize.clean_node!(node, {
        elements: %w[iframe embed],
        attributes: {
          all: %w[allowfullscreen frameborder height src width]
        }
      })

      { node_whitelist: [node] }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slodown-0.1.3 lib/slodown/embed_transformer.rb
slodown-0.1.2 lib/slodown/embed_transformer.rb