diff --git a/nh3.pyi b/nh3.pyi index a272512..a31693b 100644 --- a/nh3.pyi +++ b/nh3.pyi @@ -3,6 +3,7 @@ from typing import Callable, Dict, Optional, Set def clean( html: str, tags: Optional[Set[str]] = None, + clean_content_tags: Optional[Set[str]] = None, attributes: Optional[Dict[str, Set[str]]] = None, attribute_filter: Optional[Callable[[str, str, str]], Optional[str]] = None, strip_comments: bool = True, diff --git a/src/lib.rs b/src/lib.rs index 69413f3..20c0b42 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ use pyo3::types::{PyString, PyTuple}; #[pyfunction(signature = ( html, tags = None, + clean_content_tags = None, attributes = None, attribute_filter = None, strip_comments = true, @@ -18,6 +19,7 @@ fn clean( py: Python, html: &str, tags: Option>, + clean_content_tags: Option>, attributes: Option>>, attribute_filter: Option, strip_comments: bool, @@ -31,6 +33,7 @@ fn clean( let cleaned = py.allow_threads(|| { if tags.is_some() + || clean_content_tags.is_some() || attributes.is_some() || attribute_filter.is_some() || !strip_comments @@ -40,6 +43,9 @@ fn clean( if let Some(tags) = tags { cleaner.tags(tags); } + if let Some(tags) = clean_content_tags { + cleaner.clean_content_tags(tags); + } if let Some(mut attrs) = attributes { if let Some(generic_attrs) = attrs.remove("*") { cleaner.generic_attributes(generic_attrs); diff --git a/tests/test_nh3.py b/tests/test_nh3.py index 96a5362..cb87768 100644 --- a/tests/test_nh3.py +++ b/tests/test_nh3.py @@ -18,6 +18,13 @@ def test_clean(): nh3.clean('baidu', link_rel=None) == 'baidu' ) + assert ( + nh3.clean( + "", + clean_content_tags={"script", "style"}, + ) + == "" + ) def test_clean_with_attribute_filter():