use crate::ast::{safe_html, HtmlElement, Node};
pub fn default_disallowed_tags() -> Vec<String> {
vec![
"title".to_string(),
"textarea".to_string(),
"style".to_string(),
"xmp".to_string(),
"iframe".to_string(),
"noembed".to_string(),
"noframes".to_string(),
"script".to_string(),
"plaintext".to_string(),
]
}
pub fn gfm_safe_html(element: HtmlElement) -> Node {
safe_html(element, &default_disallowed_tags())
}
pub fn make_html_gfm_safe(node: &Node) -> Node {
match node {
Node::HtmlElement(element) => gfm_safe_html(element.clone()),
Node::Document(children) => {
Node::Document(children.iter().map(make_html_gfm_safe).collect())
}
Node::Paragraph(children) => {
Node::Paragraph(children.iter().map(make_html_gfm_safe).collect())
}
Node::BlockQuote(children) => {
Node::BlockQuote(children.iter().map(make_html_gfm_safe).collect())
}
Node::Heading {
level,
content,
heading_type,
} => Node::Heading {
level: *level,
content: content.iter().map(make_html_gfm_safe).collect(),
heading_type: heading_type.clone(),
},
Node::Emphasis(children) => {
Node::Emphasis(children.iter().map(make_html_gfm_safe).collect())
}
Node::Strong(children) => Node::Strong(children.iter().map(make_html_gfm_safe).collect()),
Node::Strikethrough(children) => {
Node::Strikethrough(children.iter().map(make_html_gfm_safe).collect())
}
Node::Link {
url,
title,
content,
} => Node::Link {
url: url.clone(),
title: title.clone(),
content: content.iter().map(make_html_gfm_safe).collect(),
},
Node::Image { url, title, alt } => Node::Image {
url: url.clone(),
title: title.clone(),
alt: alt.iter().map(make_html_gfm_safe).collect(),
},
_ => node.clone(),
}
}