Skip to content

Commit

Permalink
release: 0.1.0 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
marksweb authored Dec 19, 2023
1 parent ee4f688 commit 4173684
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ci:
autoupdate_schedule: monthly

default_language_version:
python: python3.11
python: python3.12

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ Changelog
unreleased
----------

0.1.0 - 2023-12-19
------------------

- Add templatetags to clean HTML within django templates by `@wes-otf`_ in `PR 16`_.

.. _@wes-otf: https://github.com/wes-otf
.. _PR 16: https://github.com/marksweb/django-nh3/pull/16

0.0.3 - 2023-11-15
------------------

Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = django_nh3
version = 0.0.3
version = 0.1.0
description = Django integration with for nh3, Python binding to Ammonia HTML sanitizer Rust crate.
long_description = file: README.rst
long_description_content_type = text/x-rst
Expand All @@ -10,11 +10,12 @@ author_email = [email protected]
license = MIT
license_files = LICENSE
classifiers =
Development Status :: 3 - Alpha
Development Status :: 4 - Beta
Framework :: Django :: 3.2
Framework :: Django :: 4.0
Framework :: Django :: 4.1
Framework :: Django :: 4.2
Framework :: Django :: 5.0
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Natural Language :: English
Expand Down
2 changes: 1 addition & 1 deletion src/django_nh3/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def formfield(
) -> FormField:
"""Makes the field for a ModelForm"""

# If field doesn't have any choices add kwargs expected by BleachField.
# If field doesn't have any choices add kwargs expected by Nh3Field.
if not self.choices:
kwargs.update(
{
Expand Down
10 changes: 4 additions & 6 deletions src/django_nh3/templatetags/nh3_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@


@register.filter(name="nh3")
def nh3_value(value: str | None, tags: str | None = None) -> SafeText:
def nh3_value(value: str | None, tags: str | None = None) -> SafeText | None:
"""
Takes an input HTML value and sanitizes it utilizing nh3,
returning a SafeText object that can be rendered by Django.
Accepts an optional argument of allowed tags. Should be a comma delimited
string (ie. "img,span" or "img")
string (i.e. "img,span" or "img")
"""
if value is None:
return None

args = {}

nh3_args = get_nh3_default_options()
if tags is not None:
args = nh3_args.copy()
args["tags"] = set(tags.split(","))
else:
args = nh3_args

nh3_value = nh3.clean(value, **args)
return mark_safe(nh3_value)
clean_value = nh3.clean(value, **args)
return mark_safe(clean_value)

0 comments on commit 4173684

Please sign in to comment.