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

Python rich_text.DbWhitelister类代码示例

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

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



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

示例1: test_clean_tag_node_with_data_linktype

 def test_clean_tag_node_with_data_linktype(self):
     soup = BeautifulSoup(
         '<a data-linktype="document" data-id="1" irrelevant="baz">foo</a>'
     )
     tag = soup.a
     DbWhitelister.clean_tag_node(soup, tag)
     self.assertEqual(str(tag), '<a id="1" linktype="document">foo</a>')
开发者ID:asmaps,项目名称:wagtail,代码行数:7,代码来源:test_rich_text.py


示例2: test_clean_tag_node

 def test_clean_tag_node(self):
     soup = BeautifulSoup(
         '<a irrelevant="baz">foo</a>'
     )
     tag = soup.a
     DbWhitelister.clean_tag_node(soup, tag)
     self.assertEqual(str(tag), '<a>foo</a>')
开发者ID:asmaps,项目名称:wagtail,代码行数:7,代码来源:test_rich_text.py


示例3: test_clean_tag_node_div

 def test_clean_tag_node_div(self):
     soup = BeautifulSoup(
         '<div>foo</div>'
     )
     tag = soup.div
     self.assertEqual(tag.name, 'div')
     DbWhitelister.clean_tag_node(soup, tag)
     self.assertEqual(tag.name, 'p')
开发者ID:asmaps,项目名称:wagtail,代码行数:8,代码来源:test_rich_text.py


示例4: test_clean_tag_node_with_data_embedtype

 def test_clean_tag_node_with_data_embedtype(self):
     soup = BeautifulSoup(
         '<p><a data-embedtype="image" data-id=1 data-format="left" data-alt="bar" irrelevant="baz">foo</a></p>'
     )
     tag = soup.p
     DbWhitelister.clean_tag_node(soup, tag)
     self.assertEqual(str(tag),
                      '<p><embed alt="bar" embedtype="image" format="left" id="1"/></p>')
开发者ID:asmaps,项目名称:wagtail,代码行数:8,代码来源:test_rich_text.py


示例5: test_whitelist_hooks

    def test_whitelist_hooks(self):
        # wagtail.tests.wagtail_hooks overrides the whitelist to permit <blockquote> and <a target="...">
        input_html = (
            '<blockquote>I would put a tax on all people who'
            ' <a href="https://twitter.com/DMReporter/status/432914941201223680/photo/1"'
            ' target="_blank" tea="darjeeling">'
            'stand in water</a>.</blockquote><p>- <character>Gumby</character></p>'
        )
        output_html = DbWhitelister.clean(input_html)
        expected = (
            '<blockquote>I would put a tax on all people who'
            ' <a href="https://twitter.com/DMReporter/status/432914941201223680/photo/1"'
            ' target="_blank">stand in water</a>.</blockquote><p>- Gumby</p>'
        )
        self.assertHtmlEqual(expected, output_html)

        # check that the base Whitelister class is unaffected by these custom whitelist rules
        input_html = (
            '<blockquote>I would put a tax on all people who'
            ' <a href="https://twitter.com/DMReporter/status/432914941201223680/photo/1" target="_blank"'
            ' tea="darjeeling">stand in water</a>.</blockquote><p>- <character>Gumby</character></p>'
        )
        output_html = Whitelister.clean(input_html)
        expected = (
            'I would put a tax on all people who'
            ' <a href="https://twitter.com/DMReporter/status/432914941201223680/photo/1">'
            'stand in water</a>.<p>- Gumby</p>'
        )
        self.assertHtmlEqual(expected, output_html)
开发者ID:DimiC,项目名称:wagtail,代码行数:29,代码来源:test_dbwhitelister.py


示例6: test_document_link_is_rewritten

 def test_document_link_is_rewritten(self):
     input_html = (
         '<p>Look at our <a data-linktype="document" data-id="1" href="/documents/1/brochure.pdf">'
         'horribly oversized brochure</a></p>'
     )
     output_html = DbWhitelister.clean(input_html)
     expected = '<p>Look at our <a linktype="document" id="1">horribly oversized brochure</a></p>'
     self.assertHtmlEqual(expected, output_html)
开发者ID:DimiC,项目名称:wagtail,代码行数:8,代码来源:test_dbwhitelister.py


示例7: test_page_link_is_rewritten

 def test_page_link_is_rewritten(self):
     input_html = (
         '<p>Look at the <a data-linktype="page" data-id="2" href="/">lovely homepage</a>'
         ' of my <a href="http://wagtail.io/">Wagtail</a> site</p>'
     )
     output_html = DbWhitelister.clean(input_html)
     expected = (
         '<p>Look at the <a linktype="page" id="2">lovely homepage</a>'
         ' of my <a href="http://wagtail.io/">Wagtail</a> site</p>'
     )
     self.assertHtmlEqual(expected, output_html)
开发者ID:DimiC,项目名称:wagtail,代码行数:11,代码来源:test_dbwhitelister.py


示例8: test_media_embed_is_rewritten

 def test_media_embed_is_rewritten(self):
     input_html = (
         '<p>OMG look at this video of a kitten: '
         '<iframe data-embedtype="media" data-url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" width="640"'
         ' height="480" src="//www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe></p>'
     )
     output_html = DbWhitelister.clean(input_html)
     expected = (
         '<p>OMG look at this video of a kitten:'
         ' <embed embedtype="media" url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" /></p>'
     )
     self.assertHtmlEqual(expected, output_html)
开发者ID:DimiC,项目名称:wagtail,代码行数:12,代码来源:test_dbwhitelister.py


示例9: test_image_embed_is_rewritten

 def test_image_embed_is_rewritten(self):
     input_html = (
         '<p>OMG look at this picture of a kitten:</p><figure data-embedtype="image" data-id="5"'
         ' data-format="image-with-caption" data-alt="A cute kitten" class="fancy-image">'
         '<img src="/media/images/kitten.jpg" width="320" height="200" alt="A cute kitten" />'
         '<figcaption>A kitten, yesterday.</figcaption></figure>'
     )
     output_html = DbWhitelister.clean(input_html)
     expected = (
         '<p>OMG look at this picture of a kitten:</p><embed embedtype="image" id="5"'
         ' format="image-with-caption" alt="A cute kitten" />'
     )
     self.assertHtmlEqual(expected, output_html)
开发者ID:DimiC,项目名称:wagtail,代码行数:13,代码来源:test_dbwhitelister.py


示例10: test_div_conversion

 def test_div_conversion(self):
     # DIVs should be converted to P, and all whitelist / conversion rules still applied
     input_html = (
         '<p>before</p><div class="shiny">OMG <b>look</b> at this <blink>video</blink> of a kitten: '
         '<iframe data-embedtype="media" data-url="https://www.youtube.com/watch?v=dQw4w9WgXcQ"'
         ' width="640" height="480"'
         ' src="//www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe></div><p>after</p>'
     )
     output_html = DbWhitelister.clean(input_html)
     expected = (
         '<p>before</p><p>OMG <b>look</b> at this video of a kitten:'
         ' <embed embedtype="media" url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" /></p><p>after</p>'
     )
     self.assertHtmlEqual(expected, output_html)
开发者ID:DimiC,项目名称:wagtail,代码行数:14,代码来源:test_dbwhitelister.py


示例11: test_whitelist_hooks

    def test_whitelist_hooks(self):
        """Test that DbWhitelister does not strip new elements and attributes.

        The new allowed elements and attributes are added in v1.wagtail_hooks.
        """

        input_html = '''
<span class="schema-container"
      itemprop="step"
      itemscope=""
      itemtype="http://schema.org/HowToSection">
    <h4 itemprop="name">Step 1: Learn about the debt</h4>
    <span class="schema-container" itemprop="itemListElement">
        <table>
            <thead>
                <tr>
                    <th>Col 1 header</th>
                    <th>Col 2 header</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Row 1 Col 1</td>
                    <td>Row 1 Col 2</td>
                </tr>
                <tr>
                    <td>Row 2 Col 1</td>
                    <td>Row 2 Col 2</td>
                </tr>
            </tbody>
        </table>
    </span>
</span>
        '''
        output_html = DbWhitelister.clean(input_html)
        self.assertHTMLEqual(input_html, output_html)
开发者ID:chosak,项目名称:cfgov-refresh,代码行数:36,代码来源:test_wagtail_hooks.py


示例12: value_from_datadict

 def value_from_datadict(self, data, files, name):
     original_value = super(HalloRichTextArea, self).value_from_datadict(data, files, name)
     if original_value is None:
         return None
     return DbWhitelister.clean(original_value)
开发者ID:kapito,项目名称:wagtail,代码行数:5,代码来源:rich_text.py


示例13: test_clean_tag_node_div

 def test_clean_tag_node_div(self):
     soup = BeautifulSoup("<div>foo</div>", "html5lib")
     tag = soup.div
     self.assertEqual(tag.name, "div")
     DbWhitelister.clean_tag_node(soup, tag)
     self.assertEqual(tag.name, "p")
开发者ID:torchbox-dans,项目名称:wagtail,代码行数:6,代码来源:test_rich_text.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.camelcase_to_underscore函数代码示例发布时间:2022-05-26
下一篇:
Python rich_text.expand_db_html函数代码示例发布时间: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