10000 Add a script to enable colour in HTML produced from IPython notebooks · thecodingchicken/python-future@8b2ff17 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b2ff17

Browse files
committed
Add a script to enable colour in HTML produced from IPython notebooks
1 parent eb070aa commit 8b2ff17

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
A script to re-enable colour in .html files produced from IPython notebooks.
6+
7+
Based on a script in a GitHub gist with this copyright notice:
8+
9+
#----------------------------------------------------------------------------
10+
# Copyright (c) 2013 - Damián Avila
11+
#
12+
# Distributed under the terms of the Modified BSD License.
13+
#
14+
# A little snippet to fix @media print issue printing slides from IPython
15+
#-----------------------------------------------------------------------------
16+
"""
17+
18+
import io
19+
import sys
20+
21+
notebook = sys.argv[1]
22+
assert notebook.endswith('.html')
23+
# notebook = 'jevans.ipynb'
24+
path = notebook[:-5] + '.html'
25+
flag = u'@media print{*{text-shadow:none !important;color:#000 !important'
26+
27+
with io.open(path, 'r') as in_file:
28+
data = in_file.readlines()
29+
for i, line in enumerate(data):
30+
if line[:64] == flag:
31+
data[i] = data[i].replace('color:#000 !important;', '')
32+
33+
with io.open(path, 'w') as out_file:
34+
out_file.writelines(data)
35+
36+
print("You can now print your slides")

0 commit comments

Comments
 (0)
0