-
Notifications
You must be signed in to change notification settings - Fork 227
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
TypeError: clean() got an unexpected keyword argument 'styles' #494
Comments
If you're using a normal form (not ModelForm), you may avoid using SummernoteTextFormField() or SummernoteTextField(). Just use the widget SummernoteInplaceWidget() or any widget. I faced the same issue and that's how I solved it. Anyway you sould not use it now. Consider having something like : |
I am using an older version of the bleach library. To resolve the issue, I uninstalled it and then reinstalled version 4.1.0 using the command pip install bleach==4.1.0 |
An alternative to pinning to an older version of import bleach
from bleach.css_sanitizer import CSSSanitizer
from django.forms import fields
from django_summernote import settings as summernote_settings
from django_summernote.widgets import SummernoteWidget
class RichTextField(fields.CharField):
def __init__(self, *args, **kwargs):
kwargs.update({"widget": SummernoteWidget()})
super().__init__(*args, **kwargs)
def to_python(self, value):
value = super().to_python(value)
return bleach.clean(
value,
attributes=summernote_settings.ATTRIBUTES,
css_sanitizer=CSSSanitizer(allowed_css_properties=summernote_settings.STYLES),
tags=summernote_settings.ALLOWED_TAGS,
)
# or, using nh3, instead of bleach
# See https://daniel.feldroy.com/posts/2023-06-converting-from-bleach-to-nh3
return nh3.clean(
value,
attributes={k: set(v) for k, v in summernote_settings.ATTRIBUTES.items()},
tags=set(summernote_settings.ALLOWED_TAGS),
url_schemes={"http", "https", "mailto"},
) Bleach no longer accepts the This is most likely what the EDIT: Added option for integration with |
In PR #499, bleach was replaced by nh3. |
clean of bleach does not have styles but why it is passing here I do not understand!
return bleach.clean( value, tags=ALLOWED_TAGS, attributes=ATTRIBUTES, styles=STYLES)
Below is the clean of bleach:
def clean( text, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES, protocols=ALLOWED_PROTOCOLS, strip=False, strip_comments=True, css_sanitizer=None, ):
The text was updated successfully, but these errors were encountered: