Module: Sanitize::Transformers

Defined in:
lib/sanitize/transformers/clean_css.rb,
lib/sanitize/transformers/clean_cdata.rb,
lib/sanitize/transformers/clean_comment.rb,
lib/sanitize/transformers/clean_doctype.rb,
lib/sanitize/transformers/clean_element.rb

Defined Under Namespace

Modules: CSS Classes: CleanElement

Constant Summary collapse

CleanCDATA =
lambda do |env|
  node = env[:node]

  if node.type == Nokogiri::XML::Node::CDATA_SECTION_NODE
    node.replace(Nokogiri::XML::Text.new(node.text, node.document))
  end
end
CleanComment =
lambda do |env|
  node = env[:node]

  if node.type == Nokogiri::XML::Node::COMMENT_NODE
    node.unlink unless env[:is_allowlisted]
  end
end
CleanDoctype =
lambda do |env|
  return if env[:is_allowlisted]

  node = env[:node]

  if node.type == Nokogiri::XML::Node::DTD_NODE
    if env[:config][:allow_doctype]
      if node.name != "html"
        document = node.document
        node.unlink
        document.create_internal_subset("html", nil, nil)
      end
    else
      node.unlink
    end
  end
end