• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python rich_text.expand_db_html函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wagtail.wagtailcore.rich_text.expand_db_html函数的典型用法代码示例。如果您正苦于以下问题:Python expand_db_html函数的具体用法?Python expand_db_html怎么用?Python expand_db_html使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了expand_db_html函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: richtext

def richtext(value):
    if value is not None:
        html = expand_db_html(value)
    else:
        html = ""

    return mark_safe(html)
开发者ID:poremchuk,项目名称:declarations.com.ua,代码行数:7,代码来源:wagtail_core.py


示例2: parse_links

def parse_links(html, encoding=None):
    """Process all links in given html and replace them if markup is added."""
    if encoding is None:
        encoding = settings.DEFAULT_CHARSET

    # The passed HTML may be a string or bytes, depending on what is calling
    # this method. For example, Django response.content is always bytes. We
    # always want this content to be a string for our purposes.
    html_as_text = force_text(html, encoding=encoding)

    # This call invokes Wagail-specific logic that converts references to
    # Wagtail pages, documents, and images to their proper link URLs.
    expanded_html = expand_db_html(html_as_text)

    soup = BeautifulSoup(expanded_html, 'html.parser')
    link_tags = get_link_tags(soup)
    for tag in link_tags:
        original_link = str(tag)
        link_with_markup = add_link_markup(tag)
        if link_with_markup:
            expanded_html = expanded_html.replace(
                original_link,
                link_with_markup
            )

    return expanded_html
开发者ID:cfpb,项目名称:cfgov-refresh,代码行数:26,代码来源:middleware.py


示例3: raw

def raw(value):
    if value is not None:
        html = expand_db_html(value)
    else:
        html = ''

    return mark_safe(html)
开发者ID:jordij,项目名称:bctt.nz,代码行数:7,代码来源:core_tags.py


示例4: richtext

def richtext(value):
    if value is not None:
        html = expand_db_html(value)
    else:
        html = ''

    return mark_safe('<div class="rich-text">' + html + '</div>')
开发者ID:AustinBurns,项目名称:wagtail,代码行数:7,代码来源:wagtailcore_tags.py


示例5: richtext

def richtext(value):
    if isinstance(value, RichText):
        # passing a RichText value through the |richtext filter should have no effect
        return value
    elif value is None:
        html = ''
    else:
        html = expand_db_html(value)

    return mark_safe('<div class="rich-text">' + html + '</div>')
开发者ID:Anlim,项目名称:wagtail,代码行数:10,代码来源:wagtailcore_tags.py


示例6: simplerichtext

def simplerichtext(value):
    """
    Simple richtext filter to avoid the wrapping <div class='richtext'></div> markup
    """
    if isinstance(value, SimpleRichText):
        html = value
    elif value is None:
        html = ""
    else:
        html = expand_db_html(value)

    return mark_safe(html)
开发者ID:springload,项目名称:wagtailblocks,代码行数:12,代码来源:commonblocks_tags.py


示例7: test_expand_db_html_with_embed

 def test_expand_db_html_with_embed(self, oembed):
     oembed.return_value = {
         "title": "test title",
         "author_name": "test author name",
         "provider_name": "test provider name",
         "type": "test type",
         "thumbnail_url": "test thumbnail url",
         "width": "test width",
         "height": "test height",
         "html": "test html",
     }
     html = '<embed embedtype="media" url="http://www.youtube.com/watch" />'
     result = expand_db_html(html)
     self.assertIn("test html", result)
开发者ID:torchbox-dans,项目名称:wagtail,代码行数:14,代码来源:test_rich_text.py


示例8: parse_links

def parse_links(value):
    if isinstance(value, RichText):
        soup = BeautifulSoup(expand_db_html(value.source), 'html.parser')
    else:
        soup = BeautifulSoup(expand_db_html(value), 'html.parser')

    # This removes style tags <style>
    for s in soup('style'):
        s.decompose()

    # This removes all inline style attr's
    for tag in soup.recursiveChildGenerator():
        try:
            del tag['style']
        except:
            # 'NavigableString' object has does not have attr's
            pass

    # This adds the link markup
    link_tags = get_link_tags(soup)
    add_link_markup(link_tags)

    return soup
开发者ID:amymok,项目名称:cfgov-refresh,代码行数:23,代码来源:__init__.py


示例9: test_expand_db_html_with_embed

 def test_expand_db_html_with_embed(self, oembed):
     oembed.return_value = {
         'title': 'test title',
         'author_name': 'test author name',
         'provider_name': 'test provider name',
         'type': 'test type',
         'thumbnail_url': 'test thumbnail url',
         'width': 'test width',
         'height': 'test height',
         'html': 'test html'
     }
     html = '<embed embedtype="media" url="http://www.youtube.com/watch" />'
     result = expand_db_html(html)
     self.assertIn('test html', result)
开发者ID:asmaps,项目名称:wagtail,代码行数:14,代码来源:test_rich_text.py


示例10: parse_links

def parse_links(html, encoding=None):
    """Process all links in given html and replace them if markup is added."""
    if encoding is None:
        encoding = settings.DEFAULT_CHARSET
    html = html.decode(encoding)
    html = expand_db_html(html)
    soup = BeautifulSoup(html, 'html.parser')
    link_tags = get_link_tags(soup)
    for tag in link_tags:
        original_link = str(tag)
        link_with_markup = add_link_markup(tag)
        if link_with_markup:
            html = html.replace(original_link, link_with_markup)

    return html.encode(encoding)
开发者ID:contolini,项目名称:cfgov-refresh,代码行数:15,代码来源:middleware.py


示例11: accessible_links

 def accessible_links(html):
     """
     Makes footer links with surrounding text accessible
     to screen readers by adding an aria-label attribute
     containing the full text of the footer item to the link.
     """
     soup = BeautifulSoup(expand_db_html(html), 'html.parser')
     for p in soup.find_all('p'):
         if p.find_all('a'):
             for child in p.children:
                 if child.name == 'a':
                     if child.string != p.text:
                         child['aria-label'] = p.text
                 else:
                     if child.name != 'span':
                         child = child.wrap(soup.new_tag('span'))
                     child['aria-hidden'] = 'true'
     return text_type(soup).replace(u'\xa0', ' ')
开发者ID:cfpb,项目名称:cfgov-refresh,代码行数:18,代码来源:menu_item.py


示例12: item_extra_kwargs

    def item_extra_kwargs(self, item):
        """
        Returns an extra keyword arguments dictionary that is used with
        the 'add_item' call of the feed generator.
        Add the fields of the item, to be used by the custom feed generator.
        """
        if use_feed_image:
            feed_image = item.feed_image
            if feed_image:
                image_complete_url = urljoin(
                    self.get_site_url(), feed_image.file.url
                )
            else:
                image_complete_url = ""

        content_field = getattr(item, self.item_content_field)
        try:
            content = expand_db_html(content_field)
        except:
            content = content_field.__html__()

        soup = BeautifulSoup(content, 'html.parser')
        # Remove style attribute to remove large botton padding
        for div in soup.find_all("div", {'class': 'responsive-object'}):
            del div['style']
        # Add site url to image source
        for img_tag in soup.findAll('img'):
            if img_tag.has_attr('src'):
                img_tag['src'] = urljoin(self.get_site_url(), img_tag['src'])

        fields_to_add = {
            'content': soup.prettify(formatter="html"),
        }

        if use_feed_image:
            fields_to_add['image'] = image_complete_url
        else:
            fields_to_add['image'] = ""

        return fields_to_add
开发者ID:Parbhat,项目名称:django-wagtail-feeds,代码行数:40,代码来源:feeds.py


示例13: item_extra_kwargs

    def item_extra_kwargs(self, item):
        """
        Returns an extra keyword arguments dictionary that is used with
        the 'add_item' call of the feed generator.
        Add the fields of the item, to be used by the custom feed generator.
        """
        feed_image = item.feed_image
        if feed_image:
            filter, _ = Filter.objects.get_or_create(spec='width-1200')
            img = feed_image.get_rendition(filter)

            image_complete_url = urljoin(self.get_site_url(), img.url)

        content = expand_db_html(getattr(item, self.item_content_field))
        soup = BeautifulSoup(content, 'html.parser')
        for img_tag in soup.findAll('img'):
            img_tag['src'] = urljoin(self.get_site_url(), img_tag['src'])

        return {
            'image': image_complete_url if feed_image else "",
            'content': soup.prettify(formatter="html")
        }
开发者ID:ilendl2,项目名称:django-wagtail-feeds,代码行数:22,代码来源:feeds.py


示例14: get_html

    def get_html(news_stories, additional_link_params, header_html, extra_html, footer_html):
        html = "<html><head></head><body>" + header_html
        html = html + "<ul>"
        for news_story in news_stories.order_by('-story_date'):
            url = 'https://loop.lib.uchicago.edu' + news_story.url_path.replace('/loop', '', 1) + '?' + urllib.parse.urlencode(additional_link_params)
            html = html + "<li><a href='" + url + "'>"
            html = html + news_story.title 
            html = html + "</a></li>"
        html = html + "</ul>"
        html = html + extra_html
        html = html + footer_html
        html = html + "</body></html>"

        # rough pass to clean strangely nested elements.
        soup = BeautifulSoup(html, "lxml")

        # do more cleanup work. 
        html = clean_html(str(soup))

        # get the real links for things like documents and internal pages. 
        html = expand_db_html(html)

        return html
开发者ID:uchicago-library,项目名称:library_website,代码行数:23,代码来源:utils.py


示例15: test_expand_db_html_with_linktype

 def test_expand_db_html_with_linktype(self):
     html = '<a id="1" linktype="document">foo</a>'
     result = expand_db_html(html)
     self.assertEqual(result, '<a>foo</a>')
开发者ID:asmaps,项目名称:wagtail,代码行数:4,代码来源:test_rich_text.py


示例16: item_description

 def item_description(self, item):
     return expand_db_html(item.body)
开发者ID:Mindaug,项目名称:akl.lt,代码行数:2,代码来源:feeds.py


示例17: render

 def render(self, name, value, attrs=None):
     if value is None:
         translated_value = None
     else:
         translated_value = expand_db_html(value, for_editor=True)
     return super(HalloRichTextArea, self).render(name, translated_value, attrs)
开发者ID:kapito,项目名称:wagtail,代码行数:6,代码来源:rich_text.py


示例18: get_context

 def get_context(self, request, page):
     from wagtail.wagtailcore.rich_text import expand_db_html
     context = super().get_context(request, page)
     context['content'] = expand_db_html(self.body)
     return context
开发者ID:bkfox,项目名称:aircox,代码行数:5,代码来源:sections.py


示例19: item_content

 def item_content(self, item):
     return expand_db_html(item.body)
开发者ID:apihackers,项目名称:wapps,代码行数:2,代码来源:feeds.py


示例20: test_expand_db_html_with_embed

 def test_expand_db_html_with_embed(self, get_embed):
     from wagtail.wagtailembeds.models import Embed
     get_embed.return_value = Embed(html='test html')
     html = '<embed embedtype="media" url="http://www.youtube.com/watch" />'
     result = expand_db_html(html)
     self.assertIn('test html', result)
开发者ID:kapito,项目名称:wagtail,代码行数:6,代码来源:test_rich_text.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python rich_text.DbWhitelister类代码示例发布时间:2022-05-26
下一篇:
Python models.UserPagePermissionsProxy类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap