• Stars
    star
    375
  • Rank 114,096 (Top 3 %)
  • Language
    Jupyter Notebook
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use Jupyter Notebook in mkdocs

mkdocs-jupyter: Use Jupyter Notebooks in mkdocs

  • Demo Site
  • Add Jupyter Notebooks directly to the mkdocs navigation
  • Support for multiple formats:
  • Same style as regular Jupyter Notebooks
    • Support Jupyter Themes
  • Option to execute the notebook before converting
  • Support for ipywidgets
  • Support for mkdocs TOC
  • Option to include notebook source

mkdocs-jupyter default theme mkdocs-jupyter material theme

Installation

pip install mkdocs-jupyter

Configuration

In the mkdocs.yml use Jupyter notebooks (.ipynb) or Python scripts (.py) as pages:

nav:
  - Home: index.md
  - Notebook page: notebook.ipynb
  - Python file: python_script.py

plugins:
  - mkdocs-jupyter

Titles and Table of Contents

The first h1 header (#) in your notebook will be used as the title.

# This H1 header will be the the title.

This can be turned off in the configuration (in which case the filename will be used as title):

plugins:
  - mkdocs-jupyter:
      ignore_h1_titles: True

In order to see the table of contents you need to maintain a hierarchical headers structure in your notebooks. You must use h2 headers (##) and not h1 (#)

## This H2 title will show in the table of contents

If you want to nest headers in the TOC you need to add additional levels later in the same markdown cell or new bottom markdown cells:

## This header will show as top level in the table of contents

<content>

### This one will be displayed inside the above level

Including or Ignoring Files

You can control which files are included or ignored via lists of glob patterns:

plugins:
  - mkdocs-jupyter:
      include: ["*.ipynb"] # Default: ["*.py", "*.ipynb"]
      ignore: ["some-irrelevant-files/*.ipynb"]

Execute Notebook

You can tell the plugin to execute the notebook before converting, default is False:

plugins:
  - mkdocs-jupyter:
      execute: true

You can tell the plugin to ignore the execution of some files (with glob matching):

plugins:
  - mkdocs-jupyter:
      execute_ignore:
        - "my-secret-files/*.ipynb"

To fail when notebook execution fails set allow_errors to false:

plugins:
  - mkdocs-jupyter:
      execute: true
      allow_errors: false

Kernel

By default the plugin will use the kernel specified in the notebook to execute it. You can specify a custom kernel name to use for all the notebooks:

plugins:
  - mkdocs-jupyter:
      kernel_name: python3

Ingore Code Input

By default the plugin will show full code and regular cell output details. You can hide cell code input for all the notebooks:

plugins:
  - mkdocs-jupyter:
      show_input: False

You can also decide to hide the Out[#] output notation and other cell metadata for all the notebooks:

plugins:
  - mkdocs-jupyter:
      no_input: True

Remove Cell Using Tags

By default the plugin will show full code and regular cell output details. You can hide cell code input for specific cells using tags:

plugins:
  - mkdocs-jupyter:
      remove_tag_config:
        remove_input_tags:
          - hide_code

More detailed on removing cell based on tag, see NbConvert Customization)

Jupyter themes

You can configure the different Jupyter themes. For example if using material with slate color scheme you can use the Jupyter Lab dark theme:

plugins:
  - mkdocs-jupyter:
      theme: dark

theme:
  name: material
  palette:
    scheme: slate

Extra CSS classes

This option will add a custom CSS class to the div container that highlights the code cells. This can be useful to add custom styles to the code cells.

plugins:
  - mkdocs-jupyter:
      highlight_extra_classes: "custom-css-classes

RequireJS

By default RequireJS is not loaded. You can enable it with:

plugins:
  - mkdocs-jupyter:
      include_requirejs: true

Download notebook link

You can tell the plugin to include the notebook source to make it easy to show a download button in the theme, default is False:

plugins:
  - mkdocs-jupyter:
      include_source: True

This setting will also create a page.nb_url value that you can use in your theme to make a link in each page.

For example in mkdocs-material (see customization), you can create a main.html file like this:

{% extends "base.html" %}

{% block content %}
{% if page.nb_url %}
    <a href="{{ page.nb_url }}" title="Download Notebook" class="md-content__button md-icon">
        {% include ".icons/material/download.svg" %}
    </a>
{% endif %}

{{ super() }}
{% endblock content %}

Download Notebook button

Styles

This extensions includes the Jupyter Lab nbconvert CSS styles and does some modifications to make it as generic as possible in order for it to work with a variety of mkdocs themes. This is not always possible and the theme we test the most is mkdocs-material.

It's possible you might need to do some CSS changes to make it look as good as you want, for example for the material theme take a look at their customization docs.

Create a main.html file like:

{% extends "base.html" %}

{% block content %}
{{ super() }}

<style>
// Do whatever changes you need here

.jp-RenderedHTMLCommon p {
    color: red
}

</style>
{% endblock content %}

Mkdocs Material notes

Any markdown specific features such as admonitions wont work with mkdocs-jupyter because those features are not supported by Jupyter itself and we use nbconvert to make the conversion.

To use this type of features you have to define the HTML directly in the markdown cells:

<div class="admonition note">
  <p class="admonition-title">Note</p>
  <p>
    If two distributions are similar, then their entropies are similar, implies
    the KL divergence with respect to two distributions will be smaller...
  </p>
</div>

More Repositories

1

word2vec

Python interface to Google word2vec
C
2,566
star
2

pelican-jupyter

Pelican plugin for blogging with Jupyter/IPython Notebooks
Jupyter Notebook
423
star
3

tsne

A python wrapper for Barnes-Hut tsne
C++
405
star
4

jupyter-flex

Build dashboards using Jupyter Notebooks
JavaScript
315
star
5

s3contents

Jupyter Notebooks in S3 - Jupyter Contents Manager implementation
Python
244
star
6

copper

Fast, easy and intuitive machine learning prototyping.
Python
124
star
7

PythonFinance

basic Python Finance Package
Python
104
star
8

espn-nba-scrapy

NBA Data mining
Python
70
star
9

demucs-service

Use DEMUCS to split songs into multiple sources
Python
23
star
10

polyaxon-argo-seldon-example

Model management example using Polyaxon, Argo and Seldon
Python
23
star
11

demucs-app

Use DEMUCS to split songs into multiple sources
JavaScript
20
star
12

datasciencebox

Create and manage instances for data science
Python
20
star
13

danielfrg.com

Source for danielfrg.com
HTML
20
star
14

gcp-llm-retrieval-augmentation

A retrieval augmentation LLM demo in GCP
Jupyter Notebook
18
star
15

harvard-cs109-fall-2013

Harvard CS 109 - Data Science - Fall 2013
Python
14
star
16

jupyterhub-kubernetes_spawner

JupyterHub Kubernete Spawner
Python
14
star
17

django-hospital

Python
12
star
18

storm-sklearn

from zero to storm cluster for realtime classification using sklearn
Python
12
star
19

terraform-cloudera

Terraform module for Cloudera Manager
HCL
11
star
20

illusionist

Interactive client-only reports based on Jupyter Notebooks and Jupyter widgets.
Python
11
star
21

docker-conda-repo

Docker container for creating and serving a custom conda repo/channel
Python
11
star
22

docker-selenium

docker-selenium
Jupyter Notebook
11
star
23

salt-conda

Salt states for Continuum Analytics conda python package manager
Python
9
star
24

django_crawler

A django blog crawler
Python
9
star
25

kaggle-word2vec

Kaggle word2vec NLP tutorial
Python
8
star
26

sublime-open

Open files quicker and easier: Dynamic browsing or a static list of files
Python
7
star
27

semafor-parsing

Parsing web content on SEMAFOR at scale using salt and celery
Python
6
star
28

coursera-comp-for-data-analysis

Coursera Computing for Data Analysis - Fall 2012
R
5
star
29

kaggle-yelp-recruiting-competition

Python
5
star
30

nbviewer.js

Render Jupyter Notebooks in the browser using only JS
JavaScript
5
star
31

remote-pip

Install pip packages in remote hosts
Python
4
star
32

web-template-go-react

Template for Go + React + TS
Go
3
star
33

reproduceit-538-baltimore-black-income

ReproduceIt: How Baltimore’s Young Black Men Are Boxed In
3
star
34

kaggle-bulldozers

Python
3
star
35

spark-plot

Simplifies plotting Spark DataFrames by making calculations for plots inside Spark
Jupyter Notebook
3
star
36

github-archive

The simplest script to make an archive of a Github user/org
Shell
3
star
37

kaggle-data-science-london

Python
3
star
38

coursera-data-analysis

Coursera Data Analysis - Fall 2012
Python
2
star
39

docker-multicorn

Hello world of multicorn in a docker container
Shell
2
star
40

newtask

Desktop python app to create new tasks on major task management web apps
Python
2
star
41

atom-nbviewer

Atom plugin to preview Jupyter Notebooks
JavaScript
2
star
42

docker-rpi2xc

Docker container to cross-compile for the rpi2
CMake
1
star
43

ec2hosts

Update /etc/hosts from ec2 instances
Python
1
star
44

pydata-nyc-2015

PyData NYC 2015
HTML
1
star
45

awesome-google-ads-api

A curated list of awesome Google Ads API resources
1
star
46

actions-dashboard

Dashboard for my GitHub Actions
1
star
47

remote-conda

Install conda packages in remote hosts
Go
1
star
48

cyhdfs3

Cython based wrapper for libhdfs3
Python
1
star
49

adsctl

Google Ads Control CLI and prompt
Python
1
star
50

ml-notes

Personal tools and notebooks for machine learning
Jupyter Notebook
1
star
51

grpc-up-and-running

Rust
1
star
52

atom-lighttable-syntax

An attempt of a Light Table syntax theme for atom
CSS
1
star
53

kaggle-salt

https://www.kaggle.com/c/tgs-salt-identification-challenge
Jupyter Notebook
1
star
54

reproduceit-538-adam-sandler-movies

ReproduceIt: The Three Types Of Adam Sandler Movies
1
star
55

django-ddns

Django DDNS app using AppFog as Paas.
Python
1
star
56

coursera-computational-investing-part-I

Computational Investing Part I - Fall 2012
1
star