-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect - thank you!
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
, andNH3_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.