当前位置: 首页>>代码示例>>Python>>正文


Python bleach.ALLOWED_TAGS属性代码示例

本文整理汇总了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 
开发者ID:NicolasLM,项目名称:feedsubs,代码行数:22,代码来源:html_processing.py

示例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"]) 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:10,代码来源:staff_notifications.py

示例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) 
开发者ID:Palanaeum,项目名称:palanaeum,代码行数:7,代码来源:models.py

示例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) 
开发者ID:PonyConf,项目名称:PonyConf,代码行数:7,代码来源:utils.py

示例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) 
开发者ID:puffinrocks,项目名称:puffin,代码行数:7,代码来源:applications.py

示例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) 
开发者ID:OpenHumans,项目名称:open-humans,代码行数:14,代码来源:utilities.py

示例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>&lt;script&gt;x&lt;/script&gt;</td>
    <td>&lt;p&gt;y&lt;/p&gt;</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>&lt;script&gt;x&lt;/script&gt;</td>
    <td><p>y</p></td>
    <td><em>y</em></td>
   </tr>"""
    assert expected in out.getvalue() 
开发者ID:holzschu,项目名称:Carnets,代码行数:33,代码来源:test_html.py


注:本文中的bleach.ALLOWED_TAGS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。