Python 漂白:有什么方法可以去除不允许而不是允许的标签吗?
Python Bleach: is there any way to strip tags that are disallowed rather than allowed?
我知道 Bleach 会获取 ALLOWED_TAGS
的列表,并在执行 clean()
.
时删除不在该列表中的所有标签
有没有办法根据那些被定义为不允许的标签来翻转和剥离标签?换句话说,首先假设所有内容都是允许的,然后去除所有不允许的标签。
例如,如果有 DISALLOWED_TAGS
设置,则该列表中的任何内容都将被删除。但是,我不知道有这样的选项。
我考虑过将 ALLOWED_TAGS
设置为一个函数(正如 ALLOWED_ATTRIBUTES
允许的那样),但它似乎只接受一个列表。
我同样对 ALLOWED_STYLES
是否可以做到这一点感兴趣。
我只是从理论的角度来看这个问题,而不是它是否真的是最佳实践。
不行,专门针对Bleach,没办法,以后也不支持了。页面上带有 project goals 的第一个条目表示 Bleach 将...
Always take a allowed-list-based approach
Bleach should always take a allowed-list-based approach to markup filtering. Specifying disallowed lists is error-prone and not future proof.
For example, you should have to opt-in to allowing the onclick attribute, not opt-out of all the other on* attributes. Future versions of HTML may add new event handlers, like ontouch, that old disallow would not prevent.
我知道 Bleach 会获取 ALLOWED_TAGS
的列表,并在执行 clean()
.
有没有办法根据那些被定义为不允许的标签来翻转和剥离标签?换句话说,首先假设所有内容都是允许的,然后去除所有不允许的标签。
例如,如果有 DISALLOWED_TAGS
设置,则该列表中的任何内容都将被删除。但是,我不知道有这样的选项。
我考虑过将 ALLOWED_TAGS
设置为一个函数(正如 ALLOWED_ATTRIBUTES
允许的那样),但它似乎只接受一个列表。
我同样对 ALLOWED_STYLES
是否可以做到这一点感兴趣。
我只是从理论的角度来看这个问题,而不是它是否真的是最佳实践。
不行,专门针对Bleach,没办法,以后也不支持了。页面上带有 project goals 的第一个条目表示 Bleach 将...
Always take a allowed-list-based approach
Bleach should always take a allowed-list-based approach to markup filtering. Specifying disallowed lists is error-prone and not future proof.
For example, you should have to opt-in to allowing the onclick attribute, not opt-out of all the other on* attributes. Future versions of HTML may add new event handlers, like ontouch, that old disallow would not prevent.