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


Python rich_text.DbWhitelister类代码示例

本文整理汇总了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;未经允许,请勿转载。