How to use the premailer.merge_style.csstext_to_pairs 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 liuwons / EverMark / premailer / premailer.py View on Github external
new_selector = selector
            class_ = ''
            if ':' in selector:
                new_selector, class_ = re.split(':', selector, 1)
                class_ = ':%s' % class_
            # Keep filter-type selectors untouched.
            if class_ in FILTER_PSEUDOSELECTORS:
                class_ = ''
            else:
                selector = new_selector

            sel = CSSSelector(selector)
            items = sel(page)
            if len(items):
                # same so process it first
                processed_style = csstext_to_pairs(style)

                for item in items:
                    item_id = id(item)
                    if item_id not in elements:
                        elements[item_id] = {
                            'item': item,
                            'classes': [],
                            'style': [],
                        }

                    elements[item_id]['style'].append(processed_style)
                    elements[item_id]['classes'].append(class_)

        # Now apply inline style
        # merge style only once for each element
        # crucial when you have a lot of pseudo/classes
github peterbe / premailer / premailer / premailer.py View on Github external
class_ = ""
            if ":" in selector:
                new_selector, class_ = re.split(":", selector, 1)
                class_ = ":%s" % class_
            # Keep filter-type selectors untouched.
            if class_ in FILTER_PSEUDOSELECTORS or class_.startswith(":nth-child"):
                class_ = ""
            else:
                selector = new_selector

            assert selector
            sel = _create_cssselector(selector)
            items = sel(page)
            if len(items):
                # same so process it first
                processed_style = csstext_to_pairs(
                    style, validate=not self.disable_validation
                )

                for item in items:
                    item_id = id(item)
                    if item_id not in elements:
                        elements[item_id] = {"item": item, "classes": [], "style": []}

                    elements[item_id]["style"].append(processed_style)
                    elements[item_id]["classes"].append(class_)

        # Now apply inline style
        # merge style only once for each element
        # crucial when you have a lot of pseudo/classes
        # and a long list of elements
        for _, element in elements.items():