本文整理汇总了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)
示例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
示例3: raw
def raw(value):
if value is not None:
html = expand_db_html(value)
else:
html = ''
return mark_safe(html)
示例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>')
示例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>')
示例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)
示例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)
示例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
示例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)
示例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)
示例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', ' ')
示例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
示例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")
}
示例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
示例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>')