-
-
Notifications
You must be signed in to change notification settings - Fork 68
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:create cleanify
into utils
modules
#75
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #75 +/- ##
==========================================
- Coverage 81.60% 81.20% -0.40%
==========================================
Files 3 3
Lines 125 133 +8
==========================================
+ Hits 102 108 +6
- Misses 23 25 +2 ☔ View full report in Codecov by Sentry. |
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.
Congratulations on your first PR!
The overall changes are good, but there are a few small things that could be improved, see the comments for details.
CHANGES.rst
Outdated
0.5.2 | ||
----- | ||
|
||
Release date: 2023/12/09 |
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.
No need to add a specific date here, I will update it when I make the new release.
Release date: 2023/12/09 | |
Release date: N/A |
CHANGES.rst
Outdated
|
||
Release date: 2023/12/09 | ||
|
||
- add ``cleanify`` function to ``flask_ckeditor.utils`` |
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.
- add ``cleanify`` function to ``flask_ckeditor.utils`` | |
- Add ``cleanify`` function to ``flask_ckeditor.utils`` for HTML sanity. |
flask_ckeditor/utils.py
Outdated
try: | ||
import bleach | ||
except ImportError: | ||
warnings.warn('bleach is not installed,`cleanify` function will not be available') |
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.
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.') |
flask_ckeditor/utils.py
Outdated
"""clean the input from client, this function rely on bleach, | ||
|
||
|
||
Args: |
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.
Use the docstring style that matches the existing code.
flask_ckeditor/utils.py
Outdated
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)) |
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.
You can simplify the code to this:
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)) | |
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=allow_tags or default_allowed_tags)) |
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.
cool, i got it !
Thank you for your patient review ! |
i commit a new test case for |
cleanify
into utils
moudelcleanify
into utils
modules
- Add docs - Update dependencies - Add extras_require config - Remove the linkify call as it's kind of unexpected behavior of this function
Merged, thanks! I made some improvements at 16779d8 |
hey grey, 根据代码厨房开源松的指示,我已经创建了人生中第一个pr哈哈哈,我认为把这个函数叫做
cleanify
感觉还不错,有点类似flask里面的jsonify
,我也加入了一些单元测试,麻烦有空的时候review一下啦,如果有不足的地方请提出来,我可以修改并从中受益,感谢。