File size: 785 Bytes
7a71a69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Support e-mail templates in Markdown.
"""
import markdown


class MarkdownTemplate(object):
    """
    An e-mail template formatted in Markdown.
    """
    def __init__(self, subject, body):
        """
        Initializes a Markdown template.
        """
        self._subject = subject
        self._body = body


    def evaluate(self, context):
        """
        Evaluates the markdown source in the given context, producing HTML
        and (Markdown) plain text. Also interpolates the subject line with
        the given context.
        """
        headers = {"Subject": self._subject.format(**context)}

        md = self._source.format(**context)
        html = markdown.markdown(md)
        parts = {"text/html": html, "text/plain": md}
        return headers, parts