Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
first attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerdave committed Mar 27, 2017
1 parent 6677901 commit f53aff0
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 6 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ recursive-include docs *.rst conf.py Makefile make.bat

include versioneer.py
include remarker/_version.py
include remarker/templates/*
1 change: 1 addition & 0 deletions remarker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
__version__ = get_versions()['version']
del get_versions

from . import presentation
41 changes: 38 additions & 3 deletions remarker/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
import click
import pkg_resources
from . import presentation

DEFAULT_HTML_FILE = pkg_resources.resource_filename('remarker', 'templates/default.html')
DEFAULT_CSS_FILE = pkg_resources.resource_filename('remarker', 'templates/default.css')

def loadfile(filename):
with open(filename) as infile:
return infile.read()

@click.argument('slides_markdown_file', type=click.Path(exists=True))
@click.option('--html-template', type=click.Path(exists=True),
default=DEFAULT_HTML_FILE)
@click.option('--css-file', type=click.Path(exists=True),
default=DEFAULT_CSS_FILE)
@click.option('--output-file', '-o', type=click.Path(),
default='presentaiton.html')
@click.option('--title', '-t', default='Presentation')
@click.option('--verbose', '-v', is_flag=True)
@click.command()
def cli():
click.echo("Hello, World!")
def remarker(slides_markdown_file, html_template, css_file, output_file,
title, verbose):
if verbose:
click.echo('Input:')
click.echo('slides_markdown_file: {}'.format(slides_markdown_file))
click.echo('html-template: {}'.format(html_template))
click.echo('css-file: {}'.format(css_file))
click.echo('Output file: {}'.format(output_file))


template_html = loadfile(html_template)
slide_markdown = loadfile(slides_markdown_file)
stylesheet_html = loadfile(css_file)

click.echo(stylesheet_html)
with open(output_file, 'w') as outfile:
output_html = presentation.generate_html(template_html, slide_markdown,
stylesheet_html, title=title)
outfile.write(output_html)

if __name__ == '__main__':
cli()
remarker()
22 changes: 22 additions & 0 deletions remarker/presentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from jinja2 import Template

DEFAULT_JAVASCRIPT = """
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script>var slideshow = remark.create();</script>"""

def generate_html(template_html, slide_markdown, stylesheet_html, title=None):
""" Generate HTML for a Reveal.js presentation given a template_html,
slide_markdown contents, and stylesheet_html. """

# only support inline css for now, maybe links in the future
stylesheet_html = '<style>\n{0}</style'.format(stylesheet_html)
presentation = {
'stylesheet_html': stylesheet_html,
'slide_source': slide_markdown,
'title': title,
}
remark = {
'javascript': DEFAULT_JAVASCRIPT,
}
template = Template(template_html)
return template.render(presentation=presentation, remark=remark)
4 changes: 2 additions & 2 deletions remarker/templates/default.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<title>{{ presentation.title }}</title>
<meta charset="utf-8">
{{ presentation.inline_css }}
{{ presentation.stylesheet_html }}
</head>
<body>
<textarea id="source">
Expand Down
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
click
jinja2
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
# pip-compile --output-file requirements.txt requirements.in
#
click==6.7
jinja2==2.9.5
markupsafe==1.0 # via jinja2
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
requirements = [
# TODO: put package requirements here
'click',
'jinja2',
]

test_requirements = [
Expand All @@ -37,7 +38,7 @@
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
entry_points={
'console_scripts':[
'remarker=remarker.cli:cli',
'remarker=remarker.cli:remarker',
],
},
include_package_data=True,
Expand Down
17 changes: 17 additions & 0 deletions tests/data/default_slides.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

class: center, middle

# Title

---

# Agenda

1. Introduction
2. Deep-dive
3. ...

---

# Introduction

44 changes: 44 additions & 0 deletions tests/data/presentaiton.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<title>Presentation</title>
<meta charset="utf-8">
<style>
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);

body { font-family: 'Droid Serif'; }
h1, h2, h3 {
font-family: 'Yanone Kaffeesatz';
font-weight: normal;
}
.remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; }
</style
</head>
<body>
<textarea id="source">

class: center, middle

# Title

---

# Agenda

1. Introduction
2. Deep-dive
3. ...

---

# Introduction


</textarea>

<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script>var slideshow = remark.create();</script>
</body>
</html>

0 comments on commit f53aff0

Please sign in to comment.