當前位置: 首頁>>代碼示例>>Python>>正文


Python bleach.linkify方法代碼示例

本文整理匯總了Python中bleach.linkify方法的典型用法代碼示例。如果您正苦於以下問題:Python bleach.linkify方法的具體用法?Python bleach.linkify怎麽用?Python bleach.linkify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bleach的用法示例。


在下文中一共展示了bleach.linkify方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: preview_body

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def preview_body(target, value, oldvalue, initiator):
        allowed_tags = [
            'a', 'abbr', 'acronym', 'b', 'img', 'blockquote', 'code',
            'em', 'i', 'li', 'ol', 'pre', 'strong', 'ul', 'h1', 'h2',
            'h3', 'p'
        ]
        target.body_html = bleach.linkify(bleach.clean(
            markdown(value, output_format='html'),
            tags=allowed_tags, strip=True,
            attributes={
                '*': ['class'],
                'a': ['href', 'rel'],
                'img': ['src', 'alt'],  # 支持標簽和屬性
            }
        ))

    # 把文章轉換成JSON格式的序列化字典 
開發者ID:Blackyukun,項目名稱:Simpleblog,代碼行數:19,代碼來源:models.py

示例2: pre_save

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def pre_save(self, model_instance, add):
        instance = model_instance
        value = None

        for attr in self.source.split('.'):
            value = getattr(instance, attr)
            instance = value

        if value is None or value == '':
            return value

        extensions = [
            'markdown.extensions.extra',
            'markdown.extensions.codehilite',
        ]

        md = markdown.Markdown(extensions=extensions)
        value = md.convert(value)
        value = bleach_value(value)
        value = bleach.linkify(value)

        setattr(model_instance, self.attname, value)

        return value 
開發者ID:zmrenwu,項目名稱:django-mptt-comments,代碼行數:26,代碼來源:models.py

示例3: convert_markdown

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def convert_markdown(text):
    # https://pythonadventures.wordpress.com/tag/markdown/
    allowed_tags = [
        'a', 'abbr', 'acronym', 'b',
        'blockquote', 'code', 'em',
        'i', 'li', 'ol', 'pre', 'strong',
        'ul', 'h1', 'h2', 'h3', 'p', 'br', 'ins', 'del',
    ]
    unsafe_html = markdown.markdown(
        text,
        extensions=["markdown.extensions.fenced_code"],
    )
    html = bleach.linkify(bleach.clean(unsafe_html, tags=allowed_tags))
    return Markup(html)

# Timezones. Be cautious with using tzinfo argument. http://pytz.sourceforge.net/
# "tzinfo argument of the standard datetime constructors 'does not work'
# with pytz for many timezones." 
開發者ID:okpy,項目名稱:ok,代碼行數:20,代碼來源:utils.py

示例4: process_text_links

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def process_text_links(text):
    """Process links in text, adding some attributes and linkifying textual links."""
    link_callbacks = [callbacks.nofollow, callbacks.target_blank]

    def link_attributes(attrs, new=False):
        """Run standard callbacks except for internal links."""
        href_key = (None, "href")
        if attrs.get(href_key).startswith("/"):
            return attrs

        # Run the standard callbacks
        for callback in link_callbacks:
            attrs = callback(attrs, new)
        return attrs

    return bleach.linkify(
        text,
        callbacks=[link_attributes],
        parse_email=False,
        skip_tags=["code"],
    ) 
開發者ID:jaywink,項目名稱:federation,代碼行數:23,代碼來源:text.py

示例5: post_receive

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def post_receive(self) -> None:
        """
        Make linkified tags normal tags.
        """
        super().post_receive()

        def remove_tag_links(attrs, new=False):
            rel = (None, "rel")
            if attrs.get(rel) == "tag":
                return
            return attrs

        self.raw_content = bleach.linkify(
            self.raw_content,
            callbacks=[remove_tag_links],
            parse_email=False,
            skip_tags=["code", "pre"],
        ) 
開發者ID:jaywink,項目名稱:federation,代碼行數:20,代碼來源:entities.py

示例6: markitup

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def markitup(text):
    """
    把Markdown轉換為HTML
    """

    # 刪除與段落相關的標簽,隻留下格式化字符的標簽
    # allowed_tags = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code',
    #                 'em', 'i', 'li', 'ol', 'pre', 'strong', 'ul',
    #                 'h1', 'h2', 'h3', 'p', 'img']
    return bleach.linkify(markdown(text, ['extra'], output_format='html5'))
    # return bleach.linkify(bleach.clean(
    #     # markdown默認不識別三個反引號的code-block,需開啟擴展
    #     markdown(text, ['extra'], output_format='html5'),
    #     tags=allowed_tags, strip=True))


# 權限 
開發者ID:adisonhuang,項目名稱:flask-blog,代碼行數:19,代碼來源:models.py

示例7: on_changed_body

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def on_changed_body(target, value, oldvalue, initiator):
        allowed_tags = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code',
                        'em', 'i', 'li', 'ol', 'pre', 'strong', 'ul',
                        'h1', 'h2', 'h3', 'p']
        target.body_html = bleach.linkify(bleach.clean(
            markdown(value, output_format='html'),
            tags=allowed_tags, strip=True)) 
開發者ID:CircleCI-Public,項目名稱:circleci-demo-python-flask,代碼行數:9,代碼來源:models.py

示例8: on_changed_body

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def on_changed_body(target, value, oldvalue, initiator):
        allowed_tags = [
            'a', 'abbr', 'acronym', 'b', 'code', 'em', 'img', 'i', 'strong'
        ]
        target.body_html = bleach.linkify(bleach.clean(
            markdown(value, output_format='html'),
            tags=allowed_tags, strip=True
        )) 
開發者ID:Blackyukun,項目名稱:Simpleblog,代碼行數:10,代碼來源:models.py

示例9: linkify_text

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def linkify_text(text):
    """ escape all html tags with bleach, then use bleach to linkify
    """
    if text:
        cleaned = bleach.clean(text, tags=[], attributes=[])
        return bleach.linkify(cleaned)
    else:
        return "" 
開發者ID:Pagure,項目名稱:pagure,代碼行數:10,代碼來源:filters.py

示例10: add_link

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def add_link(html_doc):
    return bleach.linkify(html_doc) 
開發者ID:gojuukaze,項目名稱:DeerU,代碼行數:4,代碼來源:html_helper.py

示例11: bleach_linkify

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def bleach_linkify(value):
    """
    Convert URL-like strings in an HTML fragment to links

    This function converts strings that look like URLs, domain names and email
    addresses in text that may be an HTML fragment to links, while preserving:

        1. links already in the string
        2. urls found in attributes
        3. email addresses
    """
    if value is None:
        return None

    return bleach.linkify(value, parse_email=True) 
開發者ID:marksweb,項目名稱:django-bleach,代碼行數:17,代碼來源:bleach_tags.py

示例12: htmlize

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def htmlize(text):
    """
    This helper method renders Markdown then uses Bleach to sanitize it as
    well as convert all links to actual links.
    """
    text = bleach.clean(text, strip=True)    # Clean the text by stripping bad HTML tags
    text = markdown(text)                    # Convert the markdown to HTML
    text = bleach.linkify(text)              # Add links from the text and add nofollow to existing links

    return text 
開發者ID:DistrictDataLabs,項目名稱:partisan-discourse,代碼行數:12,代碼來源:utils.py

示例13: linkfy_subject

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def linkfy_subject(self):
        """Linkifies the subject body."""
        return bleach.linkify(escape(self.body)) 
開發者ID:thetruefuss,項目名稱:elmer,代碼行數:5,代碼來源:models.py

示例14: __init__

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [as 別名]
def __init__(self):
        self.results: Dict[str, Result] = {}

        self.env = Environment(
            loader=PackageLoader("arche", "templates"),
            autoescape=select_autoescape(["html"]),
            extensions=["jinja2.ext.loopcontrols"],
        )
        self.env.filters["linkify"] = linkify 
開發者ID:scrapinghub,項目名稱:arche,代碼行數:11,代碼來源:report.py

示例15: markdown

# 需要導入模塊: import bleach [as 別名]
# 或者: from bleach import linkify [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


注:本文中的bleach.linkify方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。