How to use the premailer.transform 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 insula1701 / maxpress / maxpress.py View on Github external
md = Markdown()

    # 将markdown列表转化为带序号的普通段落(纯为适应微信中列表序号样式自动丢失的古怪现象)
    if convert_list:
        blocks = text.split('\n```')
        for i in range(0, len(blocks)):
            if i % 2 == 0:
                blocks[i] = re.sub(r'(\n\d+)(\.\s.*?)', r'\n\1\\\2', blocks[i])
                blocks[i] = re.sub(r'\n[\-\+\*](\s.*?)',
                                   u'\n\n{} \1'.format(ul_style), blocks[i])
            else:
                continue  # 跳过代码块内部内容
        text = '\n```'.join(blocks)

    inner_html = md(text)
    result = premailer.transform(pack_html(inner_html, styles, poster, banner))
    return result
github nandoflorestan / kerno / kerno / email / pyramid.py View on Github external
def html(self):
        """Return the rich text version of the email message."""
        html = render(self.HTML_TEMPLATE, self.adict)
        return premailer.transform(html)  # Inline CSS styles
github litchfield / django-fancymail / fancymail / emailrelated.py View on Github external
def message(self):
        for filename in self.related_ids.keys():
            self.body = self.body.replace(filename, 'cid:' + self._get_content_id(filename))
        try:
            from premailer import transform
            self.body = transform(self.body, base_url=self.base_url)
        except ImportError:
            pass
        return super(EmailMessageRelated, self).message()
github scrapinghub / spidermon / spidermon / contrib / actions / email / __init__.py View on Github external
def get_body_html(self):
        html = ""
        if self.body_html:
            html = transform(self.render_text_template(self.body_html))
        elif self.body_html_template:
            html = transform(self.render_template(self.body_html_template))
        return html
github muicss / flaskapp / flaskapp / views / auth.py View on Github external
r = EmailVerificationRequest(key=os.urandom(32).hex(), user=user)
    db.session.add(r)
    db.session.flush()

    # send email
    subject = 'Flaskapp Account: Please Confirm Email'
    msg = Message(subject, recipients=[user.email])
    verify_url = url_for('.verify_email', key=r.key, email=user.email, \
                             _external=True)

    f = '/auth/verify-email-email'
    msg.body = render_template(f + '.txt', verify_url=verify_url)

    html = render_template(f + '.html', verify_url=verify_url)
    base_url = url_for('content.home', _external=True)
    msg.html = transform(html, base_url=base_url)
    mail.send(msg)
github andyfangdz / django-asyncmailer / asyncmailer / models.py View on Github external
def get_html_content(self):
        if self.should_inline:
            return transform(self.html_content)
        return self.html_content
github websauna / websauna / websauna / system / mail / views.py View on Github external
def sample_html_email(request):
    """Render a sample of HTML email.

    This view is conditionally enabled for development sites. See :ref:`websauna.sample_html_email`.
    """

    html_body = render("email/sample.html", {}, request=request)
    html_body = premailer.transform(html_body)

    return Response(html_body)
github chris104957 / maildown / maildown / renderer.py View on Github external
if not theme:
        theme = os.path.join(os.path.dirname(os.path.abspath(__file__)), "style.css")

    if not context:
        context = {}

    with open(theme) as f:
        theme = f.read()

    markdown = mistune.Markdown(renderer=HighlightRenderer())

    with open(
        os.path.join(os.path.dirname(os.path.abspath(__file__)), "template.jinja2")
    ) as t:
        template = jinja2.Template(t.read())
    content = premailer.transform(
        template.render(content=markdown(md_content), stylesheet=theme)
    )

    new_template = jinja2.Template(content)
    return new_template.render(context)
github websauna / websauna / websauna / system / mail / __init__.py View on Github external
:param template: Template filename base string for template tripled (subject, HTML body, plain text body). For example ``email/my_message`` would map to templates ``email/my_message.subject.txt``, ``email/my_message.body.txt``, ``email/my_message.body.html``

    :param context: Template context dictionary passed to the rendererer

    :return: Tuple(subject, text_body, html_body)
    """

    subject = render(template + ".subject.txt", context, request=request)
    subject = subject.strip()

    html_body = render(template + ".body.html", context, request=request)
    text_body = render(template + ".body.txt", context, request=request)

    # Inline CSS styles
    html_body = premailer.transform(html_body)

    return subject, text_body, html_body