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

Add templatetags to clean HTML within django templates #16

Merged
merged 8 commits into from
Dec 19, 2023

Conversation

wes-otf
Copy link
Contributor

@wes-otf wes-otf commented Dec 19, 2023

This uses the original django-bleach as a guide to implement nh3 template tags that work similar to how the bleach tags did. Tags can be used in templates as a django filter to clean strings of HTML. Django settings of NH3_ALLOWED_TAGS, NH3_ALLOWED_ATTRIBUTES, and NH3_STRIP_COMMENTS to specify custom nh3 params. Unit tests were also implemented to test all newly added functionality.

Thanks for your work on this project @marksweb! This will be super useful as bleach is gradually deprecated.

@marksweb
Copy link
Owner

Awesome, thank you @wes-otf - very grateful for this. I've not had chance to get these going yet so this is a real help!



@register.filter(name="nh3")
def nh3_value(value: str | None, tags: str | None = None) -> SafeText:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a docstring on this please? Nothing complex, just something basic that descibes the fact it takes a value and will run clean on it & return a safe value to include in the template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added! Not sure if there's a specific format you prefer so I can add to it if you have a preference. Cheers!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect - thank you!

@marksweb marksweb merged commit ee4f688 into marksweb:main Dec 19, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants