Skip to content

Ammonia 3.0 upgrade #1876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 77 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ serde_json = "1.0.0"
serde = { version = "1.0.0", features = ["derive"] }
chrono = { version = "0.4.0", features = ["serde"] }
comrak = { version = "0.4.0", default-features = false }
ammonia = "2.0.0"
ammonia = "3.0.0"
docopt = "1.0"
scheduled-thread-pool = "0.2.0"
derive_deref = "1.0.0"
Expand Down
55 changes: 4 additions & 51 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,54 +22,6 @@ impl<'a> MarkdownRenderer<'a> {
/// Per `readme_to_html`, `base_url` is the base URL prepended to any
/// relative links in the input document. See that function for more detail.
fn new(base_url: Option<&'a str>) -> MarkdownRenderer<'a> {
let tags = hashset(&[
"a",
"b",
"blockquote",
"br",
"code",
"dd",
"del",
"dl",
"dt",
"em",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"hr",
"i",
"img",
"input",
"kbd",
"li",
"ol",
"p",
"pre",
"s",
"strike",
"strong",
"sub",
"sup",
"table",
"tbody",
"td",
"th",
"thead",
"tr",
"ul",
"hr",
"span",
]);
let tag_attributes = hashmap(&[
("a", hashset(&["href", "id", "target"])),
("img", hashset(&["width", "height", "src", "alt", "align"])),
("input", hashset(&["checked", "disabled", "type"])),
("th", hashset(&["rowspan", "colspan"])),
("td", hashset(&["rowspan", "colspan"])),
]);
let allowed_classes = hashmap(&[(
"code",
hashset(&[
Expand All @@ -91,11 +43,12 @@ impl<'a> MarkdownRenderer<'a> {
)]);
let sanitize_url = UrlRelative::Custom(Box::new(SanitizeUrl::new(base_url)));

let mut html_sanitizer = Builder::new();
let mut html_sanitizer = Builder::default();
html_sanitizer
.add_tags(&["input"])
.link_rel(Some("nofollow noopener noreferrer"))
.tags(tags)
.tag_attributes(tag_attributes)
.add_tag_attributes("a", &["id", "target"])
.add_tag_attributes("input", &["checked", "disabled", "type"])
.allowed_classes(allowed_classes)
.url_relative(sanitize_url)
.id_prefix(Some("user-content-"));
Expand Down