From add331408b0f207b82f3ec1b76251c700197e807 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 16 Jun 2014 19:30:53 +0200 Subject: Import slides --- slides/final/scripts/md/README.md | 5 + slides/final/scripts/md/base.html | 101 +++++++++++++++ slides/final/scripts/md/render.py | 57 +++++++++ slides/final/scripts/md/slides.md | 251 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 414 insertions(+) create mode 100644 slides/final/scripts/md/README.md create mode 100644 slides/final/scripts/md/base.html create mode 100755 slides/final/scripts/md/render.py create mode 100644 slides/final/scripts/md/slides.md (limited to 'slides/final/scripts') diff --git a/slides/final/scripts/md/README.md b/slides/final/scripts/md/README.md new file mode 100644 index 0000000..3188b3f --- /dev/null +++ b/slides/final/scripts/md/README.md @@ -0,0 +1,5 @@ +### Want to use markdown to write your slides? + +`python render.py` can do that for you. + +Dependencies: jinja2, markdown. diff --git a/slides/final/scripts/md/base.html b/slides/final/scripts/md/base.html new file mode 100644 index 0000000..5e01a30 --- /dev/null +++ b/slides/final/scripts/md/base.html @@ -0,0 +1,101 @@ + + + + + Google IO 2012 + + + + + + + + + + + + + + + + + + + + + + +
+

+

+

+ +

+
+
+ + {% for slide in slides %} + + {% if 'segue' in slide.class %} + +
+

{{- slide.title -}}

+

{{- slide.subtitle -}}

+
+ {% else %} +
+

{{- slide.title -}}

+

{{- slide.subtitle -}}

+
+
+ {{- slide.content -}} +
+ {% endif %} +
+ {% endfor %} + + +
+ +
+
+ + + +
+ + + + + + diff --git a/slides/final/scripts/md/render.py b/slides/final/scripts/md/render.py new file mode 100755 index 0000000..a035b90 --- /dev/null +++ b/slides/final/scripts/md/render.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +import codecs +import re +import jinja2 +import markdown + +def process_slides(): + with codecs.open('../../presentation-output.html', 'w', encoding='utf8') as outfile: + md = codecs.open('slides.md', encoding='utf8').read() + md_slides = md.split('\n---\n') + print 'Compiled %s slides.' % len(md_slides) + + slides = [] + # Process each slide separately. + for md_slide in md_slides: + slide = {} + sections = md_slide.split('\n\n') + # Extract metadata at the beginning of the slide (look for key: value) + # pairs. + metadata_section = sections[0] + metadata = parse_metadata(metadata_section) + slide.update(metadata) + remainder_index = metadata and 1 or 0 + # Get the content from the rest of the slide. + content_section = '\n\n'.join(sections[remainder_index:]) + html = markdown.markdown(content_section) + slide['content'] = postprocess_html(html, metadata) + + slides.append(slide) + + template = jinja2.Template(open('base.html').read()) + + outfile.write(template.render(locals())) + +def parse_metadata(section): + """Given the first part of a slide, returns metadata associated with it.""" + metadata = {} + metadata_lines = section.split('\n') + for line in metadata_lines: + colon_index = line.find(':') + if colon_index != -1: + key = line[:colon_index].strip() + val = line[colon_index + 1:].strip() + metadata[key] = val + + return metadata + +def postprocess_html(html, metadata): + """Returns processed HTML to fit into the slide template format.""" + if metadata.get('build_lists') and metadata['build_lists'] == 'true': + html = html.replace('