class Qiita::Markdown::Transformers::FilterScript
Constants
- HOST_WHITE_LIST
- URL_WHITE_LIST
Public Class Methods
call(**args)
click to toggle source
# File lib/qiita/markdown/transformers/filter_script.rb, line 16 def self.call(**args) new(**args).transform end
new(env)
click to toggle source
# File lib/qiita/markdown/transformers/filter_script.rb, line 20 def initialize(env) @env = env end
Public Instance Methods
transform()
click to toggle source
# File lib/qiita/markdown/transformers/filter_script.rb, line 24 def transform if name == "script" if URL_WHITE_LIST.include?(node["src"]) || HOST_WHITE_LIST.include?(host_of(node["src"])) node["async"] = "async" unless node.attributes.key?("async") 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_script.rb, line 45 def host_of(url) if url scheme = URI.parse(url).scheme Addressable::URI.parse(url).host if %w[http https].include? scheme end rescue Addressable::URI::InvalidURIError, URI::InvalidURIError nil end
name()
click to toggle source
# File lib/qiita/markdown/transformers/filter_script.rb, line 37 def name @env[:node_name] end
node()
click to toggle source
# File lib/qiita/markdown/transformers/filter_script.rb, line 41 def node @env[:node] end