Skip to content

Commit

Permalink
Add two additional examples for the documentation
Browse files Browse the repository at this point in the history
This should help with issues:
- messense#36
- messense#70
  • Loading branch information
HelgeKrueger committed Dec 22, 2024
1 parent 9d73a46 commit 1943dfc
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,38 @@ use pyo3::types::{PyString, PyTuple};
/// 'hi'
/// >>> nh3.clean("<b><img src='' onerror='alert(\\'hax\\')'>XSS?</b>")
/// '<b><img src="">XSS?</b>'
///
/// Example of using ``attribute_filter``:
///
/// .. code-block:: pycon
///
/// >>> from copy import deepcopy
/// >>> attributes = deepcopy(nh3.ALLOWED_ATTRIBUTES)
/// >>> attributes["a"].add("class")
/// >>> def attribute_filter(tag, attr, value):
/// ... if tag == "a" and attr == "class":
/// ... if "mention" in value.split(" "):
/// ... return "mention"
/// ... return None
/// ... return value
/// >>> nh3.clean("<a class='mention unwanted'>@foo</a>",
/// ... attributes=attributes,
/// ... attribute_filter=attribute_filter)
/// '<a class="mention" rel="noopener noreferrer">@foo</a>'
///
/// Example of maintaining the ``rel`` attribute:
///
/// .. code-block:: pycon
///
/// >>> from copy import deepcopy
/// >>> attributes = deepcopy(nh3.ALLOWED_ATTRIBUTES)
/// >>> attributes["a"].add("rel")
/// >>> nh3.clean("<a href='https://tag.example' rel='tag'>#tag</a>",
/// ... link_rel=None, attributes=attributes)
/// '<a href="https://tag.example" rel="tag">#tag</a>'


#[pyfunction(signature = (
html,
tags = None,
Expand Down

0 comments on commit 1943dfc

Please sign in to comment.