Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI that accepts markdown from stdin or file and outputs HTML presentation #1

Merged
merged 5 commits into from
Oct 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions remarkable/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,44 @@
remarkable.

Usage:
remarkable [options] command <param> <another_params>
remarkable [options] another-command <param>
remarkable [options] remark <path-to-markdown-file>

remarkable -h | --help

Options:
--kw-arg=<kw> Keyword option description.
-b --boolean Boolean option description.
--debug Debug.

-h --help Show this screen.
"""
import logging

from docopt import docopt
import logging

from jinja2 import Environment, PackageLoader

import remarkable

log = logging.getLogger(__name__)


def main():
arguments = docopt(__doc__, version=changes.__version__)
arguments = docopt(__doc__, version=remarkable.__version__)
debug = arguments['--debug']
logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)
log.debug('arguments: %s', arguments)

if arguments['remark']:
file_name = arguments['<path-to-markdown-file>']
html_file_name = '%s.html' % file_name

html = render_remark(open(file_name).read())
with open(html_file_name, 'w') as html_file:
html_file.write(html)
log.info('Created %s' % html_file_name)


def render_remark(markdown):
loader = PackageLoader('remarkable', 'templates')
env = Environment(loader=loader)
template = env.get_template('remark.html')
return template.render({'markdown': markdown})
139 changes: 139 additions & 0 deletions remarkable/templates/remark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Application To Platform</title>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Droid+Serif);
@import url(http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);

body {
font-family: 'Droid Serif';
font-size: 30px;
}
h1, h2, h3 {
font-family: 'Yanone Kaffeesatz';
font-weight: 400;
margin-bottom: 0;
}
h1 { font-size: 4em; }
h2 { font-size: 2em; }
h3 { font-size: 1.6em; }
.footnote {
position: absolute;
bottom: 3em;
}
li p { line-height: 1.25em; }
.red { color: #fa0000; }
.small { font-size: 0.5em; }
.large { font-size: 2em; }
a, a > code {
color: rgb(249, 38, 114);
text-decoration: none;
}
code {
-moz-border-radius: 5px;
-web-border-radius: 5px;
background: #e7e8e2;
border-radius: 5px;
font-size: 16px;
}
.pull-left {
float: left;
width: 47%;
}
.pull-right {
float: right;
width: 47%;
}
.pull-right ~ p {
clear: both;
}
#slideshow .slide .content code {
font-size: 0.8em;
}
#slideshow .slide .content pre code {
font-size: 0.9em;
padding: 15px;
}
.inverse {
background: #272822;
color: #777872;
text-shadow: 0 0 20px #333;
}
.inverse h1, .inverse h2 {
color: #f3f3f3;
line-height: 0.8em;
}

/* Slide-specific styling */
#slide-inverse .footnote {
bottom: 12px;
left: 20px;
}
#slide-how .slides {
font-size: 0.9em;
position: absolute;
top: 151px;
right: 140px;
}
#slide-how .slides h3 {
margin-top: 0.2em;
}
#slide-how .slides .first, #slide-how .slides .second {
padding: 1px 20px;
height: 90px;
width: 120px;
-moz-box-shadow: 0 0 10px #777;
-webkit-box-shadow: 0 0 10px #777;
box-shadow: 0 0 10px #777;
}
#slide-how .slides .first {
background: #fff;
position: absolute;
top: 20%;
left: 20%;
z-index: 1;
}
#slide-how .slides .second {
position: relative;
background: #fff;
z-index: 0;
}

/* Two-column layout */
.left-column {
color: #777;
width: 20%;
height: 92%;
float: left;
}
.left-column h2:last-of-type, .left-column h3:last-child {
color: #000;
}
.right-column {
width: 75%;
float: right;
padding-top: 2em;
}
</style>
</head>
<body>
<textarea id="source">
{{ markdown }}
</textarea>
<script src="http://gnab.github.com/remark/downloads/remark-0.5.5.min.js" type="text/javascript"></script>
<script type="text/javascript">
var hljs = remark.highlighter.engine;
</script>
<script src="remark.language.js" type="text/javascript"></script>
<script type="text/javascript">
var slideshow = remark.create({
ratio: '16:9',
highlightStyle: 'monokai',
highlightLanguage: 'python'
}) ;
</script>
</body>
</html>
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
changes < 1.0.0
coverage < 4.0.0
docopt < 1.0.0
flake8 < 3.0.0
Expand Down