How to use the premailer.premailer.Premailer function in premailer

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 / __main__.py View on Github external
"--allow-insecure-ssl",
        default=False,
        action="store_true",
        help="Skip SSL certificate verification for external URLs.",
    )

    options = parser.parse_args(args)

    if options.disable_basic_attributes:
        options.disable_basic_attributes = options.disable_basic_attributes.split()

    html = options.infile.read()
    if hasattr(html, "decode"):  # Forgive me: Python 2 compatability
        html = html.decode("utf-8")

    p = Premailer(
        html=html,
        base_url=options.base_url,
        preserve_internal_links=options.preserve_internal_links,
        exclude_pseudoclasses=options.exclude_pseudoclasses,
        keep_style_tags=options.keep_style_tags,
        include_star_selectors=options.include_star_selectors,
        remove_classes=options.remove_classes,
        strip_important=options.strip_important,
        external_styles=options.external_styles,
        css_text=options.css_text,
        method=options.method,
        base_path=options.base_path,
        disable_basic_attributes=options.disable_basic_attributes,
        disable_validation=options.disable_validation,
        allow_insecure_ssl=options.allow_insecure_ssl,
    )