How to use premailer - 10 common examples

To help you get started, we’ve selected a few premailer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github peterbe / premailer / premailer / test_premailer.py View on Github external
ok_(url.startswith('https://'))
            if 'style1.css' in url:
                return MockResponse(
                    "h1 { color: brown }"
                )
            if 'style2.css' in url:
                return MockResponse(
                    "h2 { color: pink }"
                )
            if 'style3.css' in url:
                return MockResponse(
                    "h3 { color: red }", gzip=True
                )
        urlopen = mocked_urlopen

        p = Premailer(
            html,
            base_url='https://www.peterbe.com'
        )
        result_html = p.transform()

        compare_html(expect_html, result_html)
github peterbe / premailer / premailer / test_premailer.py View on Github external
expect_html = """
        
        <title>Title</title>
        <style type="text/css">a:hover {color:purple !important}</style>
        
        
        
        <h1 style="color:orange">Hello</h1>
        <h2 style="color:green">World</h2>
        <h3 style="color:yellow">Test</h3>
        <a style="color:pink" href="#">Link</a>
        
        """

        p = Premailer(
            html,
            strip_important=False
        )
        result_html = p.transform()

        compare_html(expect_html, result_html)
github peterbe / premailer / premailer / test_premailer.py View on Github external
<a href="#">Hi!</a>
        
        """

        expect_html = """
        
        <title>Title</title>
        <style type="text/css">a:hover {color:green !important}
        a:focus {color:blue !important}</style>
        
        
        <a style="color:red" href="#">Hi!</a>
        
        """

        p = Premailer(html,
                      keep_style_tags=True,
                      strip_important=False)
        result_html = p.transform()

        compare_html(expect_html, result_html)
github peterbe / premailer / premailer / test_premailer.py View on Github external
def test_broken_xml(self):
        """Test the simplest case with xml"""

        html = """
        
        <title>Title
        &lt;style type="text/css"&gt;
        img { border: none; }
        &lt;/style&gt;
        &lt;/head&gt;
        &lt;body&gt;
        &lt;img src="test.png" alt="test"/&gt;
        &lt;/body&gt;
        """

        p = Premailer(html, method="xml")
        assert_raises(
            XMLSyntaxError,
            p.transform,
        )</title>
github peterbe / premailer / premailer / test_premailer.py View on Github external
<div class="example"></div>
        
        """

        expect_html = """
        
        
        
        <div style="color:green"></div>
        
        """

        p = Premailer(html)
        result_html = p.transform()

        compare_html(expect_html, result_html)
github peterbe / premailer / premailer / test_premailer.py View on Github external
<div class="example"></div>
        
        """

        expect_html = """
        
        
        
        <div style="color:green"></div>
        
        """

        p = Premailer(html)
        result_html = p.transform()

        compare_html(expect_html, result_html)
github peterbe / premailer / premailer / test_premailer.py View on Github external
<div id="identified" class="example"></div>
        
        """

        expect_html = """
        
        
        
        <div style="color:green" id="identified"></div>
        
        """

        p = Premailer(html)
        result_html = p.transform()

        compare_html(expect_html, result_html)
github peterbe / premailer / premailer / test_premailer.py View on Github external
expect_html = """
        
        
        
        <p style="text-align:center">Text</p>
        <table style="height:300px; width:200px">
          <tbody><tr>
            <td bgcolor="red" style="background-color:red">Cell 1</td>
            <td bgcolor="red" style="background-color:red">Cell 2</td>
          </tr>
        </tbody></table>
        
        """

        p = Premailer(
            html,
            exclude_pseudoclasses=True,
            disable_basic_attributes=['align', 'width', 'height']
        )
        result_html = p.transform()

        expect_html = re.sub('}\s+', '}', expect_html)
        result_html = result_html.replace('}\n', '}')

        compare_html(expect_html, result_html)
github peterbe / premailer / premailer / test_premailer.py View on Github external
<div>First div</div>
        
        """

        expect_html = """
        
        
        
        <div align="right" style="text-align:right">First div</div>
        
        """

        p = Premailer(html)
        result_html = p.transform()

        compare_html(expect_html, result_html)
github peterbe / premailer / premailer / test_premailer.py View on Github external
<h1>Hello</h1>
        <h2>World</h2>
        <h3>Test</h3>
        <a href="#">Link</a>
        
        """

        p = Premailer(
            html,
            strip_important=False
        )
        assert_raises(
            ExternalNotFoundError,
            p.transform,
        )