當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。