Download pool/shard004/Python/0035934_markdown.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 785 Bytes
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard004/Python/0035934_markdown.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard004/Python/0035934_markdown.py
-
curl -L -o 0035934_markdown.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard004/Python/0035934_markdown.py
785 Bytes
| """ | |
| 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 | |