Skip to content

Conversation

@zubeydecivelek
Copy link
Contributor

@zubeydecivelek zubeydecivelek commented Nov 25, 2025

Screenshot 2025-11-25 at 17 39 04 Screenshot 2025-11-25 at 17 39 58

Comment on lines +226 to +261
class SanitizedHTMLWithCSS(fields.String):
"""Enhanced SanitizedHTML supporting inline CSS sanitization.
Fully compatible with marshmallow_utils.fields.SanitizedHTML,
but adds CSS.
"""

def __init__(
self,
tags=None,
attrs=None,
css_styles=None,
*args,
**kwargs,
):
"""
:param tags: Allowed HTML tags.
:param attrs: Allowed HTML attributes per tag.
:param css_styles: List of allowed CSS properties (e.g., ["color"]).
"""
super().__init__(*args, **kwargs)

self.tags = tags
self.attrs = attrs
self.css_styles = css_styles

def _deserialize(self, value, attr, data, **kwargs):
"""Run bleach sanitize with CSS support."""
value = super()._deserialize(value, attr, data, **kwargs)

return sanitize_html(
value,
tags=self.tags,
attrs=self.attrs,
css_styles=self.css_styles,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

marshmallow_utils SanitizedHTML doesn't support css_styles

"strong": ["style"],
"em": ["style"],
"u": ["style"],
"sup": ["style"],
Copy link
Contributor

Choose a reason for hiding this comment

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

what are these attrs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked, and span and p should be enough I'll remove these

Copy link
Contributor

@ntarocco ntarocco left a comment

Choose a reason for hiding this comment

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

LGTM!

@zzacharo zzacharo merged commit bc1eb29 into CERNDocumentServer:main Nov 27, 2025
1 check 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.

3 participants