nb_offline_convert - An offline exporter for nbconvert
The normal HTML exporter of nbconvert creates the HTML files that will fetch resources (javascript and css files) from CDN, and the WebPDF exporter also depends on HTML exporter, so it's not possible to generate HTML of PDF files with widgets using nbconvert in an environement without internet connection.
This exporter allows nbconvert to export notebooks into HTML and PDF files that use all resources from the local machine by doing three steps:
- The
RequireJSfile content is injected directly into the generatedHTMLfiles. - The
ipywidgetsjavascript file (embed-amd.js), icons and fonts are bundled withnb_offline_convert.embed-amd.jsis patched to fetch icons and fonts from local paths instead of CDN - The javascript files of widgets are configured to be fetched from the local notebook extension paths.
Installation
nb_offline_convert can be installed from PyPI
pip install nb-offline-convert
Usage
- Usage in CLI
# convert to html
jupyter nbconvert --to html-offline notebook-you-want-to-convert.ipynb
# convert to pdf
jupyter nbconvert --to webpdf-offline notebook-you-want-to-convert.ipynb
The default Mathjax option is TeX-AMS_CHTML-full,Safe, to change this option, pass --OfflineHTMLExporter.mathjax_option to the command line:
# Use 'TeX-MML-AM_CHTML,Safe' option
jupyter nbconvert --to html-offline --OfflineHTMLExporter.mathjax_option=TeX-MML-AM_CHTML,Safe notebook-you-want-to-convert.ipynb
- Usage in a script
from nb_offline_convert import OfflineHTMLExporter, OfflineWebPDFExporter
# convert to html
html_converter = OfflineHTMLExporter()
content, _ = html_converter.from_filename("notebook-you-want-to-convert.ipynb")
with open("converted_file.html", "w") as f:
f.write(content)
# convert to pdf
pdf_converter = OfflineWebPDFExporter()
content, _ = pdf_converter.from_filename("notebook-you-want-to-convert.ipynb")
with open("converted_file.pdf", "wb") as f:
f.write(content)
Add mathjax_option parameter to the constructor of OfflineHTMLExporter or OfflineWebPDFExporter to modify the Mathjax option:
html_converter = OfflineHTMLExporter(mathjax_option="TeX-AMS_CHTML-full,Safe")
Development
install nb_offline_convert for development using:
git clone https://github.com/trungleduc/nb_offline_convert.git
cd nb_offline_convert
python -m pip install -e .
Metadata
Release files for nb-offline-convert 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nb_offline_convert-0.1.1.tar.gz | 5.4 MB | Without provenance | Details for nb_offline_convert-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nb_offline_convert-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for nb_offline_convert-0.1.1-py3-none-any.whl |
Total release size: 11.5 MB
Release files / nb_offline_convert-0.1.1.tar.gz
| Download URL | nb_offline_convert-0.1.1.tar.gz |
|---|---|
| Size | 5.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e78f3864c1d2a6baf567f4dd1346797efa3586281fbc4aa2fa528de6290ec49f
|
|
BLAKE2b-256 checksum How to use checksums |
88bbc22becee512ba33c71e789e4071ffc3dc87bbc776c2b3e9b43c0b2eb29ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/0.0.0 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / nb_offline_convert-0.1.1-py3-none-any.whl
| Download URL | nb_offline_convert-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfc9cae781bd2b8132701d06927966d06047b73c8363ccbba92ee129da1580ae
|
|
BLAKE2b-256 checksum How to use checksums |
36af5c6b646d7e110562277e7e9fa4e9fc4ddcb9c5664215699f03110bffbf80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/0.0.0 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Security for nb-offline-convert 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.