Skip to content

Commit

Permalink
Merge pull request #95 from wwoods/issue-93
Browse files Browse the repository at this point in the history
Fixes #93 - Embeds pdf.css reveal.js stylesheet if print-pdf in URL
  • Loading branch information
marianoguerra authored Aug 30, 2017
2 parents 5901972 + 9c42e32 commit 8c3ebe8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions html5css3/postprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def add_js(tree, embed=True, params=None):
body.append(js_fullpath(path, embed))

def revealjs(tree, embed=True, params=None):
import json

head = tree[0]
body = tree[1]
params = params or {}
Expand Down Expand Up @@ -157,6 +159,22 @@ def path(*args):

if printpdf:
head.append(css(path("css", "print", "pdf.css"), embed))
else:
# Embed print-pdf URL semantics
css_print = read_file(abspath(path("css", "print", "pdf.css")))
# Escape for HTML page
css_print = json.dumps(css_print)
script = html.Script(r"""
(function() {{
if (window.location.search.match( /print-pdf/gi )) {{
var printStyle = document.createElement( 'style' );
printStyle.type = 'text/css';
printStyle.innerHTML = {};
document.getElementsByTagName( 'head' )[0].appendChild( printStyle );
}}
}})();
""".format(css_print))
head.append(script)

# <script src="lib/js/head.min.js"></script>
# <script src="js/reveal.js"></script>
Expand Down

0 comments on commit 8c3ebe8

Please sign in to comment.