# `HtmlSanitizeEx.Scrubber.Meta`
[🔗](https://github.com/rrrene/html_sanitize_ex/blob/main/lib/html_sanitize_ex/scrubber/meta.ex#L1)

This module contains some meta-programming magic to define your own rules
for scrubbers.

The StripTags scrubber is a good starting point:

    defmodule MyStripTags do
      require HtmlSanitizeEx.Scrubber.Meta
      alias HtmlSanitizeEx.Scrubber.Meta

      # Removes any CDATA tags before the traverser/scrubber runs.
      Meta.remove_cdata_sections_before_scrub

      Meta.strip_comments

      Meta.strip_everything_not_covered
    end

You can use the `allow_tag_with_uri_attributes/3` and
`allow_tag_with_these_attributes/2` macros to define what is allowed:

    defmodule MyStripTags do
      require HtmlSanitizeEx.Scrubber.Meta
      alias HtmlSanitizeEx.Scrubber.Meta

      # Removes any CDATA tags before the traverser/scrubber runs.
      Meta.remove_cdata_sections_before_scrub

      Meta.strip_comments

      Meta.allow_tag_with_uri_attributes   "img", ["src"], ["http", "https"]
      Meta.allow_tag_with_these_attributes "img", ["width", "height"]

      Meta.strip_everything_not_covered
    end

You can stack these if convenient:

    Meta.allow_tag_with_uri_attributes   "img", ["src"], ["http", "https"]
    Meta.allow_tag_with_these_attributes "img", ["width", "height"]
    Meta.allow_tag_with_these_attributes "img", ["title", "alt"]

# `allow_tag_with_any_attributes`
*macro* 

Allow any attributes for the specified +tag+.

    Meta.allow_tag_with_any_attributes "a"

    Meta.allow_tag_with_any_attributes "img"

# `allow_tag_with_these_attributes`
*macro* 

Allow the given +list+ of attributes for the specified +tag+.

    Meta.allow_tag_with_these_attributes "a", ["name", "title"]

    Meta.allow_tag_with_these_attributes "img", ["title", "alt"]

# `allow_tag_with_this_attribute_values`
*macro* 

Allow the given list of +values+ for the given +attribute+ on the
specified +tag+.

    Meta.allow_tag_with_this_attribute_values "a", "target", ["_blank"]

# `allow_tag_with_uri_attributes`
*macro* 

Allow the given +list+ of attributes to contain URI information for the
specified +tag+.

    # Only allow SSL-enabled and mailto links
    Meta.allow_tag_with_uri_attributes "a", ["href"], ["https", "mailto"]

    # Only allow none-SSL images
    Meta.allow_tag_with_uri_attributes "img", ["src"], ["http"]

    # NOTE: this macro should always be called before other `allow_` macros for any given tag
    allow_tag_with_uri_attributes("a", ["href"], ["http", "https", "mailto"])
    allow_tag_with_these_attributes("a", ["class", "title"])

# `allow_tags_and_scrub_their_attributes`
*macro* 

Allow these tags and use the regular `scrub_attribute/2` function to scrub
the attributes.

# `remove_cdata_sections_before_scrub`
*macro* 

Removes any CDATA tags before the traverser/scrubber runs.

# `strip_comments`
*macro* 

Strips all comments.

# `strip_everything_not_covered`
*macro* 

> This macro is deprecated. You can just remove it..

Ensures any tags/attributes not explicitly whitelisted until this
statement are stripped.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
