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


Python rich_text.expand_db_html函数代码示例

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


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


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