Skip to content

Commit ce691ea

Browse files
authored
Merge pull request #48 from mlouhivu/user-js-conf
Support user defined javascript and remark configuration
2 parents a915cba + 8d85cf5 commit ce691ea

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

cicero/git.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,41 @@ def render_github_markdown(path, engine, engine_version):
8484
if style is None:
8585
style = 'default'
8686

87+
file_without_suffix, _suffix = os.path.splitext(last_file)
8788
# if own css is available, we load it
8889
# if not, we default to empty own css
8990
try:
90-
file_without_suffix, _suffix = os.path.splitext(last_file)
9191
url = prefix + '/' + file_without_suffix + '.css'
9292
response = _urlopen(url)
9393
own_css = response.read().decode("utf-8")
9494
except IOError:
9595
own_css = ''
96+
own_css = flask.Markup(own_css) # disable autoescaping
97+
# .. do the same for own javascript
98+
try:
99+
url = prefix + '/' + file_without_suffix + '.js'
100+
response = _urlopen(url)
101+
own_javascript = response.read().decode("utf-8")
102+
except IOError:
103+
own_javascript = ''
104+
# use custom configuration for the rendering engine, if available
105+
try:
106+
url = prefix + '/' + file_without_suffix + '.conf'
107+
response = _urlopen(url)
108+
own_conf = ''
109+
for line in response.readlines():
110+
own_conf += line.decode("utf-8").replace('\n', ',\n')
111+
own_conf = own_conf.rstrip('\n')
112+
except IOError:
113+
own_conf = ''
96114

97115
return flask.render_template('render.html',
98116
title=title,
99117
markdown=fix_images(markdown, prefix),
100118
style=style,
101119
own_css=own_css,
120+
own_javascript=own_javascript,
121+
own_conf=own_conf,
102122
engine='{0}-{1}'.format(engine, engine_version))
103123
except IOError:
104124
return flask.render_template('404.html')

cicero/preview.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
def home():
88
import io
99
import os
10-
from flask import current_app, render_template, render_template_string, request
10+
from flask import current_app, render_template, render_template_string, request, Markup
1111
from .title import extract_title
1212
from .images import fix_images
1313

@@ -29,12 +29,29 @@ def home():
2929
if os.path.isfile(own_css_file):
3030
with io.open(own_css_file, 'r') as css_file:
3131
own_css = css_file.read()
32+
own_css = Markup(own_css) # disable autoescaping
33+
# use own javascript, if available
34+
own_js_file = talk_no_suffix + '.js'
35+
own_javascript = ''
36+
if os.path.isfile(own_js_file):
37+
with io.open(own_js_file, 'r') as js_file:
38+
own_javascript = js_file.read()
39+
# use custom configuration for the rendering engine, if available
40+
own_conf_file = talk_no_suffix + '.conf'
41+
own_conf = ''
42+
if os.path.isfile(own_conf_file):
43+
with io.open(own_conf_file, 'r') as conf_file:
44+
for line in conf_file.readlines():
45+
own_conf += line.replace('\n', ',\n')
46+
own_conf = own_conf.rstrip('\n')
3247

3348
return render_template('render.html',
3449
title=title,
3550
markdown=markdown,
3651
style=style,
3752
own_css=own_css,
53+
own_javascript=own_javascript,
54+
own_conf=own_conf,
3855
engine=config['engine'])
3956

4057

cicero/static/engines/remark-0.13.0/js.html

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<script type="text/javascript">
2+
{{ own_javascript|indent|safe }}
23
var slideshow = remark.create({
4+
{{ own_conf|indent(8)|safe }}
35
highlightStyle: '{{ style }}',
46
highlightLines: true
57
}) ;

0 commit comments

Comments
 (0)