class Qiita::Markdown::Transformers::FilterIframe

Constants

HOST_WHITE_LIST
URL_WHITE_LIST

Public Class Methods

call(**args) click to toggle source
# File lib/qiita/markdown/transformers/filter_iframe.rb, line 15
def self.call(**args)
  new(**args).transform
end
new(env) click to toggle source
# File lib/qiita/markdown/transformers/filter_iframe.rb, line 19
def initialize(env)
  @env = env
end

Public Instance Methods

transform() click to toggle source
# File lib/qiita/markdown/transformers/filter_iframe.rb, line 23
def transform
  if name == "iframe"
    if URL_WHITE_LIST.include?(node["src"]) || HOST_WHITE_LIST.include?(host_of(node["src"]))
      node["width"] = "100%"
      node.children.unlink
    else
      node.unlink
    end
  end
end

Private Instance Methods

host_of(url) click to toggle source
# File lib/qiita/markdown/transformers/filter_iframe.rb, line 44
def host_of(url)
  if url
    scheme = URI.parse(url).scheme
    Addressable::URI.parse(url).host if ["http", "https", nil].include? scheme
  end
rescue Addressable::URI::InvalidURIError, URI::InvalidURIError
  nil
end
name() click to toggle source
# File lib/qiita/markdown/transformers/filter_iframe.rb, line 36
def name
  @env[:node_name]
end
node() click to toggle source
# File lib/qiita/markdown/transformers/filter_iframe.rb, line 40
def node
  @env[:node]
end