Releases: rrrene/html_sanitize_ex
v1.5.0-rc.0
Check it out on Hex: https://hex.pm/packages/html_sanitize_ex/1.5.0-rc.0
New API for Custom Scrubbers
Instead of importing and requiring HtmlSanitizeEx.Scrubber.Meta, just use HtmlSanitizeEx:
defmodule MyScrubber do
use HtmlSanitizeEx
allow_tag_with_these_attributes("p", ["title"])
endUsing HtmlSanitizeEx also creates a sanitize/1 function in the module, so you can just call MyScrubber.sanitize(html).
allow_tag_with_these_attributes/3 is taking a do block, which allows specific handling of attribute/value pairs:
defmodule MyScrubber do
use HtmlSanitizeEx
allow_tag_with_these_attributes("p", ["title"]) do
{"class", value} when value in ["red", "green", "blue"] ->
{"class", value}
end
endThe handler either returns a {attribute, value} pair or nil to scrub the value.
Extending existing Scrubbers
HtmlSanitizeEx can also be used for extending existing scrubbers:
defmodule MyScrubber do
use HtmlSanitizeEx, extend: :basic_html
allow_tag_with_these_attributes("p", ["title"])
endYou can extend :basic_html, :html5, :markdown_html and :strip_tags.
You can also extend any custom scrubber you created:
defmodule MyOtherScrubber do
use HtmlSanitizeEx, extend: MyScrubber
allow_tag_with_these_attributes("p", ["class"])
endThe result is a scrubber that works like the built-in BasicHTML scrubber, but also allows class and title attributes on <p> tags.