Skip to content

Commit

Permalink
fix some question about change request
Browse files Browse the repository at this point in the history
  • Loading branch information
r1cardohj committed Dec 11, 2023
1 parent ab448fc commit 8ef17b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Release date: -
0.5.2
-----

Release date: 2023/12/09
Release date: N/A

- add ``cleanify`` function to ``flask_ckeditor.utils``
- Add ``cleanify`` function to ``flask_ckeditor.utils`` for HTML sanity.


0.5.1
Expand Down
16 changes: 6 additions & 10 deletions flask_ckeditor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
try:
import bleach
except ImportError:
warnings.warn('bleach is not installed,`cleanify` function will not be available')
warnings.warn('The "bleach" library is not installed, `cleanify` function will not be available.')

Check warning on line 9 in flask_ckeditor/utils.py

View check run for this annotation

Codecov / codecov/patch

flask_ckeditor/utils.py#L8-L9

Added lines #L8 - L9 were not covered by tests


def get_url(endpoint_or_url):
Expand All @@ -23,17 +23,13 @@ def random_filename(old_filename):


def cleanify(text, *, allow_tags=None):
"""clean the input from client, this function rely on bleach,
"""Clean the input from client, this function rely on bleach.
Args:
text (str): input
allow_tags (Iterable[str], optional): if you don't want to use default `allow_tags`
you can provide a Iterable which include html tag string like ['a', 'li',...]
:parm text: input str
:parm allow_tags: if you don't want to use default `allow_tags`,
you can provide a Iterable which include html tag string like ['a', 'li',...].
"""
if allow_tags:
return bleach.linkify(bleach.clean(text, tags=allow_tags))
default_allowed_tags = {'a', 'abbr', 'b', 'blockquote', 'code',
'em', 'i', 'li', 'ol', 'pre', 'strong', 'ul',
'h1', 'h2', 'h3', 'h4', 'h5', 'p'}
return bleach.linkify(bleach.clean(text, tags=default_allowed_tags))
return bleach.linkify(bleach.clean(text, tags=allow_tags or default_allowed_tags))

0 comments on commit 8ef17b4

Please sign in to comment.