-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(markdown): convert markdown to html, then sanitize
revert the scrubber back from `html5` to a custom scrubber that is a variation of the markdown scrubber from html_sanitize_ex in addition - * add a test that covers - inputs and forms should NOT be allowed in markdown content * add a test that covers - inputs, forms, and html5 tags should be allowed within codeblocks in markdown content
- Loading branch information
Showing
3 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
defmodule Tilex.Blog.PostScrubber do | ||
@moduledoc """ | ||
PostScrubber is mostly a copy/pasta from the HtmlSanitizeEx library markdown_html scrubber | ||
The difference is below under the "additions" comment where we've added some additional customizations | ||
For more info on customizing scrubbers, see the docs for HtmlSanitizeEx | ||
""" | ||
|
||
require HtmlSanitizeEx.Scrubber.Meta | ||
alias HtmlSanitizeEx.Scrubber.Meta | ||
|
||
@valid_schemes ["http", "https", "mailto"] | ||
|
||
# Removes any CDATA tags before the traverser/scrubber runs. | ||
Meta.remove_cdata_sections_before_scrub() | ||
|
||
Meta.strip_comments() | ||
|
||
Meta.allow_tag_with_uri_attributes("a", ["href"], @valid_schemes) | ||
Meta.allow_tag_with_these_attributes("a", ["name", "title"]) | ||
|
||
Meta.allow_tag_with_this_attribute_values("a", "target", ["_blank"]) | ||
|
||
Meta.allow_tag_with_this_attribute_values("a", "rel", [ | ||
"noopener", | ||
"noreferrer" | ||
]) | ||
|
||
Meta.allow_tag_with_these_attributes("b", []) | ||
Meta.allow_tag_with_these_attributes("blockquote", []) | ||
Meta.allow_tag_with_these_attributes("br", []) | ||
Meta.allow_tag_with_these_attributes("code", ["class"]) | ||
Meta.allow_tag_with_these_attributes("del", []) | ||
Meta.allow_tag_with_these_attributes("em", []) | ||
Meta.allow_tag_with_these_attributes("h1", []) | ||
Meta.allow_tag_with_these_attributes("h2", []) | ||
Meta.allow_tag_with_these_attributes("h3", []) | ||
Meta.allow_tag_with_these_attributes("h4", []) | ||
Meta.allow_tag_with_these_attributes("h5", []) | ||
Meta.allow_tag_with_these_attributes("h6", []) | ||
Meta.allow_tag_with_these_attributes("hr", []) | ||
Meta.allow_tag_with_these_attributes("i", []) | ||
|
||
Meta.allow_tag_with_uri_attributes("img", ["src"], @valid_schemes) | ||
|
||
Meta.allow_tag_with_these_attributes("img", [ | ||
"width", | ||
"height", | ||
"title", | ||
"alt" | ||
]) | ||
|
||
Meta.allow_tag_with_these_attributes("li", []) | ||
Meta.allow_tag_with_these_attributes("ol", []) | ||
Meta.allow_tag_with_these_attributes("p", []) | ||
Meta.allow_tag_with_these_attributes("pre", []) | ||
Meta.allow_tag_with_these_attributes("span", []) | ||
Meta.allow_tag_with_these_attributes("strong", []) | ||
Meta.allow_tag_with_these_attributes("table", []) | ||
Meta.allow_tag_with_these_attributes("tbody", []) | ||
Meta.allow_tag_with_these_attributes("td", []) | ||
Meta.allow_tag_with_these_attributes("th", []) | ||
Meta.allow_tag_with_these_attributes("thead", []) | ||
Meta.allow_tag_with_these_attributes("tr", []) | ||
Meta.allow_tag_with_these_attributes("u", []) | ||
Meta.allow_tag_with_these_attributes("ul", []) | ||
|
||
# Additions | ||
Meta.allow_tag_with_these_attributes("div", []) | ||
|
||
Meta.strip_everything_not_covered() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters