Skip to main content (Source)

# ``year`` is the current year:
# ``talks`` is a list of processed form entries
from jinja2 import Template, Environment, select_autoescape, pass_eval_context
from markupsafe import Markup, escape
from IPython.core.display import HTML
import re
env = Environment(autoescape=select_autoescape(['html', 'xml']))
_paragraph_re = re.compile(r'(?:\r\n|\r(?!\n)|\n){2,}')
def nl2br(eval_ctx, value):
    result = u'\n\n'.join(u'<p>%s</p>' % p.replace('\n', Markup('<br>\n'))
                          for p in _paragraph_re.split(jinja2.filters.escape(value)))
    result = re.sub(r'(https?[/\-.:a-zA-Z0-9_]+)',r'<a href="\1">\1</a>',result)
    if eval_ctx.autoescape:
        result = Markup(result)
    return result
env.filters['br'] = nl2br
template = env.from_string("""
<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <title>EAMS {{year}} talk submissions</title>
li {
    margin: 0.5em 0;
article {
    width: 40rem;
    margin: 5rem auto 0 auto;
    line-height: 1.5em;
<h1>EAMS {{year}} talk submissions</h1>
{% for talk in talks %}
<li><a href="#talk-{{loop.index}}">{{talk.title}}</a></li>
{% endfor %}
{% for talk in talks %}
<article id="talk-{{loop.index}}">
<h1 style="font-size: 1.2em; font-weight: bold">{{talk.title|br}}</h1>
<p><a href="mailto:{{}}">{{}}</a></p>
<p style="font-style: italic">{{talk.format}}</p>
{% if talk.notes %}<p><strong>Notes:</strong> {{talk.notes|br}}</p>{% endif %}
{% endfor %}
h = template.render(year=year, talks=sorted(talks,key=lambda t: re.sub(r'\W','',t['title'].lower())))
with open('talks.html','w') as f: