Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 6217
License: OTHER
1
from IPython.display import display, HTML
2
import requests
3
4
def load_style(s):
5
"""Load a CSS stylesheet in the notebook by URL or filename.
6
7
Examples::
8
9
%load_style mystyle.css
10
%load_style http://ipynbstyles.com/otherstyle.css
11
"""
12
if s.startswith('http'):
13
r =requests.get(s)
14
style = r.text
15
else:
16
with open(s, 'r') as f:
17
style = f.read()
18
s = '<style>\n{style}\n</style>'.format(style=style)
19
display(HTML(s))
20
21
def load_ipython_extension(ip):
22
"""Load the extension in IPython."""
23
ip.register_magic_function(load_style)
24