Skip to content
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

Improve README #30

Merged
merged 1 commit into from
Dec 7, 2023
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
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ pip install nh3

## Usage

```python
import nh3

print(nh3.clean("<b><img src=\"\">I'm not trying to XSS you</b>"))
```
See [the documentation](https://nh3.readthedocs.io/en/latest/).

## Performance

Running on MacBook Air (M2, 2022)
A quick benchmark showing that nh3 is about 20 times faster than the deprecated [bleach](https://pypi.org/project/bleach/) package.
Measured on a MacBook Air (M2, 2022).

```python
```ipython
Python 3.11.0 (main, Oct 25 2022, 16:25:24) [Clang 14.0.0 (clang-1400.0.29.102)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.9.0 -- An enhanced Interactive Python. Type '?' for help.
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;
use pyo3::types::{PyString, PyTuple};

/// Sanitizes an HTML fragment in a string according to the configured options.
/// Sanitize an HTML fragment according to the given options.
///
/// :param html: Input HTML fragment
/// :type html: ``str``
Expand Down Expand Up @@ -172,7 +172,7 @@ fn clean(
Ok(cleaned)
}

/// Turn an arbitrary string into unformatted HTML
/// Turn an arbitrary string into unformatted HTML.
///
/// This function is roughly equivalent to PHP’s htmlspecialchars and htmlentities.
/// It is as strict as possible, encoding every character that has special meaning to the HTML parser.
Expand All @@ -186,11 +186,11 @@ fn clean_text(py: Python, html: &str) -> String {
py.allow_threads(|| ammonia::clean_text(html))
}

/// Determine if a given string contains HTML
/// Determine if a given string contains HTML.
///
/// This function is parses the full string into HTML and checks if the input contained any HTML syntax.
/// This function parses the full string and checks for any HTML syntax.
///
/// Note: This function will return positively for strings that contain invalid HTML syntax
/// Note: This function will return True for strings that contain invalid HTML syntax
/// like ``<g>`` and even ``Vec::<u8>::new()``.
///
/// :param html: Input string
Expand Down