当前位置: 首页>>代码示例>>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;未经允许,请勿转载。