Skip to main content

Use Jupyter in mkdocs websites

Project description

mkdocs-jupyter: Use Jupyter Notebooks in mkdocs

pypi build coverage license

  • 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

Usage

pip install mkdocs-jupyter

In your mkdocs.yml:

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

Options

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"

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

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

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 Juptyer Lab nbconvert CSS styles and does some changes 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 %}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs-jupyter-0.17.4.tar.gz (1.4 MB view details)

Uploaded Source

File details

Details for the file mkdocs-jupyter-0.17.4.tar.gz.

File metadata

  • Download URL: mkdocs-jupyter-0.17.4.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for mkdocs-jupyter-0.17.4.tar.gz
Algorithm Hash digest
SHA256 e9a858f79f2cdd71a2558c3b51787663361ec258e1f709c19aa19e8be9582fa7
MD5 c4ed1b0b9df0abdf31b959aef5adc3be
BLAKE2b-256 6018a18f3ee3b378595a0b830a8a144108634cbfd360b1e62af981e19d35bc83

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page