本文整理匯總了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()