Skip to main content

Plugin for mkdocs to generate markdown documents from jupyter notebooks.

Project description

PyPI - Python Version PyPI PyPI - Downloads GitHub contributors PyPI - License

mknotebooks

mknotebooks is a plugin for MkDocs enabling you to include Jupyter notebooks directly in your project documentation.

Install

pip3 install mknotebooks

Usage

  • Add mknotebooks to the plugin section of your mkdocs.yml
  • Include any notebooks (.ipynb files) you want to use in the docs/ directory just as you would .md files.

Example:

# mkdocs.yml
nav:
  - your_notebook.ipynb

plugins:
  - mknotebooks

Any static images, plots, etc. will be extracted from the notebook and placed alongside the output HTML.

Options

You can optionally execute the notebooks, by setting execute: true in the config. You can include a hidden preamble script, to be run before executing any cells using preamble: "<path/to/your/script>". The default cell execution timeout can be overridden by setting timeout: <timeout>, where <timeout> is an integer number of seconds.

By default, execution will be aborted if any of the cells throws an error, but you can set allow_errors: true to continue execution and include the error message in the cell output.

Example:

# mkdocs.yml
plugins:
  - mknotebooks
      execute: false
      timeout: 100
      preamble:  "<path/to/your/script>"
      allow_errors: false

Styling

Mknotebooks applies default styling to improve the appearance of notebook input/output cells and pandas dataframes. If these interfere with any other CSS stylesheets that you're using, you can disable these via the following options.

# mkdocs.yml
- mknotebooks:
   enable_default_jupyter_cell_styling: false
   enable_default_pandas_dataframe_styling: false

Syntax hightlightting

In order to enable syntax highlighting for code blocks, pygments has to be installed and codehilite extension has to be enabled in mkdocs.yml.

  1. Install pygments:
pip install Pygments
  1. Enable codehilite extension in mkdocs.yml:
# mkdocs.yml
markdown_extensions:
    - codehilite

Binder

You can also choose to have mknotebooks insert a Binder link into each notebook.

- mknotebooks:
      binder: true
      binder_service_name: "gh"
      binder_branch: "master"
      binder_ui: "lab"

If you are using GitLab, you will need to set binder_service_name to "gl".

Examples

Example docs projects demonstrating the use of a preamble and Binder are. Try them out by running pipenv install && pipenv run mkdocs serve.

Inspecting generated markdown

You can also export the generated markdown by setting write_markdown: true in your mkdocs.yml. This will write the generated markdown to a .md.tmp file alongside the original notebook.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mknotebooks-0.7.0.post0.dev310-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file mknotebooks-0.7.0.post0.dev310-py3-none-any.whl.

File metadata

  • Download URL: mknotebooks-0.7.0.post0.dev310-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.11

File hashes

Hashes for mknotebooks-0.7.0.post0.dev310-py3-none-any.whl
Algorithm Hash digest
SHA256 9d9b1d46385e5bf9b56026f9122be030b5e874188c2eb2d8078d6158372ab962
MD5 97c58ed1f8f52410bf1c90ce0a3c36f1
BLAKE2b-256 b9afef6e9a6e7d256ab73a6f6c8778a44d6ee419ce4ac55f3b86c7da6b06f869

See more details on using hashes here.

Supported by

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