-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding first stab at a Markdown/Yaml email template
- Loading branch information
1 parent
3a822bd
commit f86c6d7
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.template import Template, TemplateEncodingError | ||
from markdown import markdown | ||
import yaml | ||
#from BeautifulSoup import BeautifulSoup | ||
|
||
|
||
class MarkdownTemplate(Template): | ||
def __init__(self, template_string, origin=None, name=None): | ||
split_template = template_string.split("---\n") | ||
if len(split_template) == 3: | ||
context = yaml.load(split_template[1]) | ||
if isinstance(context, type({})): | ||
template_string = split_template[2] | ||
self.frontmatter = context | ||
try: | ||
template_string = markdown(template_string) | ||
super(Template, self).__init__( | ||
template_string, | ||
origin=origin, | ||
name=name | ||
) | ||
except UnicodeDecodeError: | ||
raise TemplateEncodingError("Templates can only be constructed " | ||
"from unicode or UTF-8 strings.") |