本文整理汇总了Python中bleach.ALLOWED_TAGS属性的典型用法代码示例。如果您正苦于以下问题:Python bleach.ALLOWED_TAGS属性的具体用法?Python bleach.ALLOWED_TAGS怎么用?Python bleach.ALLOWED_TAGS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类bleach
的用法示例。
在下文中一共展示了bleach.ALLOWED_TAGS属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_article
# 需要导入模块: import bleach [as 别名]
# 或者: from bleach import ALLOWED_TAGS [as 别名]
def clean_article(content: str, base_url: str=None,
replace_images: bool=True) -> str:
"""Clean and format an untrusted chunk of HTML.
This filter cleans the HTML from dangerous tags and formats it so that
it fits with the style of the surrounding document by shifting titles.
"""
soup = bs4.BeautifulSoup(content, 'html.parser')
remove_unwanted_tags(soup)
unify_style(soup)
rewrite_relative_links(soup, base_url)
if replace_images and READER_CACHE_IMAGES:
rewrite_image_links(soup)
content = soup.prettify()
content = bleach.clean(
content, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES, strip=True
)
return content
示例2: clean_message
# 需要导入模块: import bleach [as 别名]
# 或者: from bleach import ALLOWED_TAGS [as 别名]
def clean_message(self):
message = self.cleaned_data["message"]
return bleach.clean(
message,
tags=bleach.ALLOWED_TAGS + ["p", "pre", "span", "h1", "h2",
"h3", "h4", "h5", "h6"],
attributes=["title", "href", "style"],
styles=["text-decoration", "text-align"])
示例3: save
# 需要导入模块: import bleach [as 别名]
# 或者: from bleach import ALLOWED_TAGS [as 别名]
def save(self, *args, **kwargs):
self.text = bleach.clean(self.text, strip=True, strip_comments=True,
tags=bleach.ALLOWED_TAGS + ['p'])
self.speaker = bleach.clean(self.speaker, strip=True, strip_comments=True)
super(EntryLine, self).save(*args, **kwargs)
示例4: markdown_to_html
# 需要导入模块: import bleach [as 别名]
# 或者: from bleach import ALLOWED_TAGS [as 别名]
def markdown_to_html(md):
html = markdown(md)
allowed_tags = bleach.ALLOWED_TAGS + ['p', 'pre', 'span' ] + ['h%d' % i for i in range(1, 7) ]
html = bleach.clean(html, tags=allowed_tags)
return mark_safe(html)
示例5: init
# 需要导入模块: import bleach [as 别名]
# 或者: from bleach import ALLOWED_TAGS [as 别名]
def init():
flaskext.markdown.Markdown(app)
app.config['BLEACH_ALLOWED_TAGS'] = bleach.ALLOWED_TAGS + ["p", "h1", "h2", "h3", "h4", "h5", "h6", "img"]
app.config['BLEACH_ALLOWED_ATTRIBUTES'] = dict(bleach.ALLOWED_ATTRIBUTES, img=["src"])
flask_bleach.Bleach(app)
示例6: markdown
# 需要导入模块: import bleach [as 别名]
# 或者: from bleach import ALLOWED_TAGS [as 别名]
def markdown(value):
"""
Translate markdown to a safe subset of HTML.
"""
cleaned = bleach.clean(
markdown_library.markdown(value),
tags=bleach.ALLOWED_TAGS + ["p", "h1", "h2", "h3", "h4", "h5", "h6"],
)
linkified = bleach.linkify(cleaned)
return mark_safe(linkified)
示例7: test_raw_html_write_clean
# 需要导入模块: import bleach [as 别名]
# 或者: from bleach import ALLOWED_TAGS [as 别名]
def test_raw_html_write_clean():
"""
Test that columns can contain raw HTML which is not escaped.
"""
import bleach
t = Table([['<script>x</script>'], ['<p>y</p>'], ['<em>y</em>']], names=['a', 'b', 'c'])
# Confirm that <script> and <p> get escaped but not <em>
out = StringIO()
t.write(out, format='ascii.html', htmldict={'raw_html_cols': t.colnames})
expected = """\
<tr>
<td><script>x</script></td>
<td><p>y</p></td>
<td><em>y</em></td>
</tr>"""
assert expected in out.getvalue()
# Confirm that we can whitelist <p>
out = StringIO()
t.write(out, format='ascii.html',
htmldict={'raw_html_cols': t.colnames,
'raw_html_clean_kwargs': {'tags': bleach.ALLOWED_TAGS + ['p']}})
expected = """\
<tr>
<td><script>x</script></td>
<td><p>y</p></td>
<td><em>y</em></td>
</tr>"""
assert expected in out.getvalue()