Skip to content

Commit

Permalink
Merge pull request #48 from mlouhivu/user-js-conf
Browse files Browse the repository at this point in the history
Support user defined javascript and remark configuration
  • Loading branch information
bast committed Sep 11, 2017
2 parents a915cba + 8d85cf5 commit ce691ea
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
22 changes: 21 additions & 1 deletion cicero/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,41 @@ def render_github_markdown(path, engine, engine_version):
if style is None:
style = 'default'

file_without_suffix, _suffix = os.path.splitext(last_file)
# if own css is available, we load it
# if not, we default to empty own css
try:
file_without_suffix, _suffix = os.path.splitext(last_file)
url = prefix + '/' + file_without_suffix + '.css'
response = _urlopen(url)
own_css = response.read().decode("utf-8")
except IOError:
own_css = ''
own_css = flask.Markup(own_css) # disable autoescaping
# .. do the same for own javascript
try:
url = prefix + '/' + file_without_suffix + '.js'
response = _urlopen(url)
own_javascript = response.read().decode("utf-8")
except IOError:
own_javascript = ''
# use custom configuration for the rendering engine, if available
try:
url = prefix + '/' + file_without_suffix + '.conf'
response = _urlopen(url)
own_conf = ''
for line in response.readlines():
own_conf += line.decode("utf-8").replace('\n', ',\n')
own_conf = own_conf.rstrip('\n')
except IOError:
own_conf = ''

return flask.render_template('render.html',
title=title,
markdown=fix_images(markdown, prefix),
style=style,
own_css=own_css,
own_javascript=own_javascript,
own_conf=own_conf,
engine='{0}-{1}'.format(engine, engine_version))
except IOError:
return flask.render_template('404.html')
Expand Down
19 changes: 18 additions & 1 deletion cicero/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def home():
import io
import os
from flask import current_app, render_template, render_template_string, request
from flask import current_app, render_template, render_template_string, request, Markup
from .title import extract_title
from .images import fix_images

Expand All @@ -29,12 +29,29 @@ def home():
if os.path.isfile(own_css_file):
with io.open(own_css_file, 'r') as css_file:
own_css = css_file.read()
own_css = Markup(own_css) # disable autoescaping
# use own javascript, if available
own_js_file = talk_no_suffix + '.js'
own_javascript = ''
if os.path.isfile(own_js_file):
with io.open(own_js_file, 'r') as js_file:
own_javascript = js_file.read()
# use custom configuration for the rendering engine, if available
own_conf_file = talk_no_suffix + '.conf'
own_conf = ''
if os.path.isfile(own_conf_file):
with io.open(own_conf_file, 'r') as conf_file:
for line in conf_file.readlines():
own_conf += line.replace('\n', ',\n')
own_conf = own_conf.rstrip('\n')

return render_template('render.html',
title=title,
markdown=markdown,
style=style,
own_css=own_css,
own_javascript=own_javascript,
own_conf=own_conf,
engine=config['engine'])


Expand Down
2 changes: 2 additions & 0 deletions cicero/static/engines/remark-0.13.0/js.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script type="text/javascript">
{{ own_javascript|indent|safe }}
var slideshow = remark.create({
{{ own_conf|indent(8)|safe }}
highlightStyle: '{{ style }}',
highlightLines: true
}) ;
Expand Down

0 comments on commit ce691ea

Please sign in to comment.