Jupyter notebook styling with HTML and javascript

Dark theme for Jupyter Notebook

https://github.com/powerpak/jupyter-dark-theme

Import CSS style located on a remote server.

In [1]:
## Replace *import with @import
style="""
<style>
*import url("https://tessarinseve.pythonanywhere.com/notebookcss/custom.css")
</style>
"""
In [2]:
from IPython.display import HTML
HTML(style)
Out[2]:

Section numbering

Create incremental numbered headings.

In [3]:
%%javascript
$.getScript( "https://tessarinseve.pythonanywhere.com/js/sectionnumbering.js",
            function( data, textStatus, jqxhr ) {
});

Table of contents

Generate table of contents inside a markdown formatted cell.

In [4]:
%%javascript
$("h1, h2").each(function(i) {
                var current = $(this);
                current.attr("id", "title" + i);

                /* Create a empty markdown cell (press m) and type:
                <div id="toc">
                </div>
                */

                $("#toc").append("<a id='link" + i + "' href='#title" + i + "' title='" + current.attr("tagName") + "'>" + current.html() + "</a></br>");
                
});

Replace Logo

In [ ]:
%%javascript

$("#kernel_logo_widget").html("<img class=\"current_kernel_logo\" \
    src=\"https://tessarinseve.pythonanywhere.com/twittercard\" style=\"display: inline;width:40px;height: 30px\">")

GNU UNITS web app

In [ ]:
def gnu_units(ufrom="",uto=""):

    """ 
    Get from unit - to unit factor from gnu-units web application
    """
    try:
        import requests as rq
        import re
        from bs4 import BeautifulSoup as bs4
    except:
        raise ImportError
    
    url = "https://tessarinseve.pythonanywhere.com/units"
    se = {"from":ufrom,"to":uto}
    factor = rq.post(url, se)
    
    html = bs4(factor.text)
    output = html.find(id = "output")
    return "{}".format("".join(output.contents))
In [ ]:
print(gnu_units("BTC","EUR"))