-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: Fix rendering of html in all page (SEA-1330)
- Loading branch information
1 parent
4ca1d22
commit f866186
Showing
34 changed files
with
375 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Anything imported here will be available globally in templates | ||
# You can add more imports and functions to helpers.py as necessary to | ||
# make features available in your templates. | ||
|
||
# More info | ||
# https://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest | ||
# /templates/templates.html | ||
|
||
from markupsafe import Markup # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
from bleach.sanitizer import Cleaner # type:ignore[import-untyped] | ||
from markupsafe import Markup | ||
|
||
|
||
from typing import TypeVar | ||
|
||
|
||
_StrT = TypeVar('_StrT', bound=str) | ||
|
||
|
||
# html tags allowed by bleach | ||
SANE_HTML_TAGS = [ | ||
'a', | ||
'abbr', | ||
'b', | ||
'br', | ||
'blockquote', | ||
'code', | ||
'del', | ||
'div', | ||
'em', | ||
'i', | ||
'img', | ||
'hr', | ||
'li', | ||
'ol', | ||
'p', | ||
'pre', | ||
'strong', | ||
'sup', | ||
'span', | ||
'ul', | ||
'h1', | ||
'h2', | ||
'h3', | ||
'h4', | ||
'h5', | ||
'h6', | ||
'table', | ||
'tbody', | ||
'thead', | ||
'tr', | ||
'th', | ||
'td', | ||
] | ||
|
||
# html attributes allowed by bleach | ||
SANE_HTML_ATTRS = { | ||
'a': ['href', 'title'], | ||
'abbr': ['title', ], | ||
'acronym': ['title', ], | ||
'img': ['src', 'alt', 'title'] | ||
} | ||
|
||
|
||
cleaner = Cleaner( | ||
tags=SANE_HTML_TAGS, | ||
attributes=SANE_HTML_ATTRS | ||
) | ||
|
||
|
||
def sanitize_html(html: str | None) -> Markup: | ||
""" Takes the given html and strips all but a whitelisted number of tags | ||
from it. | ||
""" | ||
|
||
return Markup(cleaner.clean(html or '')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.