Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3
Convert Jupyter (IPython) Notebooks to static HTML
License
jirutka/ipynb2html
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
ipynb2html is a converter (renderer) of theJupyter Notebook Format 4.0+ to static HTML.It works both in Node.js and browser environment.
This repository contains the following packages, all published onnpm.
This package provides the converter itself and some utilities withno dependencies.You have to provide your own syntax highlighter and Markdown, math and ANSI sequences renderer; or not, if you don’t need them.
This package builds on the ipynb2html-core and provides a complete, ready-to-go renderer configured with:
marked as Markdown renderer,
KaTeX as math renderer,
anser as ANSI sequences renderer,
highlight.js as syntax highlighter.
It also provides a reference stylesheet which you can find indist/notebook.min.css (or non-minifiedstyles/notebook.css).
ipynb2html-cli is also provided as a single minified JavaScript with all the external dependencies bundled in.It requires only Node.js (version 10 or newer) to be installed on the system.
The archive also contains source maps (useful for debugging).
If you useAlpine Linux, you can also install it from packageipynb2html.
To render HTML in Node.js (server-side rendering), you need some (fake) DOM implementation.The recommended one isnodom — it’s lightweight,small, doesn’t have any external dependencies and ipynb2html is tested against it.However, you can choose any other if you like.
npm install ipynb2html nodomimport*asfsfrom'fs'import*asipynbfrom'ipynb2html'import{Document}from'nodom'constrenderNotebook=ipynb.createRenderer(newDocument())constnotebook=JSON.parse(fs.readFileSync('./example.ipynb','utf8'))console.log(renderNotebook(notebook).outerHTML)
You have basically two options how to use ipynb2html in the browser: use the browser bundles provided in the ipynb2html package, or build your own bundle (using e.g.Rollup orwebpack).
The provided bundles are in UMD format (AMD, CommonJS and IIFE in one file), so they should work in all environments (old and modern browsers, Node.js).They are transpiled and have injectedcore-js polyfills to be compatible with browsers that have>0.5% global coverage, Firefox ESR, and not dead browsers.
ipynb2html-full.min.js is a self-contained bundle with all the external dependencies included (marked, KaTeX, Anser and Highlight.js).
You can link it fromjsDelivr CDN, for example:
<!DOCTYPE html><html><head><metacharset="utf-8"><linkrel="stylesheet"href="https://cdn.jsdelivr.net/npm/ipynb2html@0.4.0-rc.1/dist/notebook.min.css"crossorigin="anonymous"><linkrel="stylesheet"href="https://cdn.jsdelivr.net/npm/katex@0.16.3/dist/katex.min.css"crossorigin="anonymous"><linkrel="stylesheet"href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.7.3/build/styles/default.min.css"crossorigin="anonymous"><scriptsrc="https://cdn.jsdelivr.net/npm/ipynb2html@0.4.0-rc.1/dist/ipynb2html-full.min.js"crossorigin="anonymous"></script></head> ...</html>
The bundle exposes global variableipynb2html:
constelement=ipynb2html.render(notebook)document.body.appendChild(element)
ipynb2html also provides functionautoRender that renders each notebook on the page embedded (as JSON) inside<script type="application/x-ipynb+json">...</script>.[1]
<!DOCTYPE html><html><head><metacharset="utf-8"><linkrel="stylesheet"href="https://cdn.jsdelivr.net/npm/ipynb2html@0.4.0-rc.1/dist/notebook.min.css"crossorigin="anonymous"><linkrel="stylesheet"href="https://cdn.jsdelivr.net/npm/katex@0.16.3/dist/katex.min.css"crossorigin="anonymous"><linkrel="stylesheet"href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.7.3/build/styles/default.min.css"crossorigin="anonymous"><scriptdefersrc="https://cdn.jsdelivr.net/npm/ipynb2html@0.4.0-rc.1/dist/ipynb2html-full.min.js"crossorigin="anonymous"onload="ipynb2html.autoRender();"></script></head><body><main><scripttype="application/x-ipynb+json">{"cells":[ ...],"metadata":{ ...},"nbformat":4,"nbformat_minor":3}</script></main></body><html>
ipynb2html.min.js contains only ipynb2html and ipynb2html-core code (plus polyfills).If you load marked, KaTeX, AnsiUp, and Highlight.js in the page, you will get the same functionality as withipynb2html-full.min.js:
<!DOCTYPE html><html><head><linkrel="stylesheet"href="https://cdn.jsdelivr.net/npm/katex@0.16.3/dist/katex.min.css"crossorigin="anonymous"><linkrel="stylesheet"href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.7.3/build/styles/default.min.css"crossorigin="anonymous"><scriptsrc="https://cdn.jsdelivr.net/npm/marked@4.1.1/marked.min.js"crossorigin="anonymous"></script><scriptsrc="https://cdn.jsdelivr.net/npm/ansi_up@5.0.1/ansi_up.js"crossorigin="anonymous"></script><scriptsrc="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.7.3/build/highlight.min.js"crossorigin="anonymous"></script><scriptsrc="https://cdn.jsdelivr.net/npm/katex@0.16.3/dist/katex.min.js"crossorigin="anonymous"></script><scriptsrc="https://cdn.jsdelivr.net/npm/ipynb2html@0.4.0-rc.1/dist/ipynb2html.min.js"crossorigin="anonymous"></script></head> ...</html>
Or you may use any other implementations and provide them to theipynb2html.createRenderer function.All of them are optional, but you usually need at least a Markdown renderer.
NodeJS 10.13+
Pandoc andAsciidoctor (used only for converting README.adoc to Markdown for npmjs)
TypeScript the language
ttypescript wrapper for
tscallowing to use custom AST transformersyarn for dependencies management and building
ESLint for linting JS/TypeScript code
Jest for testing
Rollup for building single-file bundles
Clone this repository:
git clone https://github.com/jirutka/ipynb2html.gitInstall Yarn (if you don’t have it already):
npm install -g yarnInstall all JS dependencies:
yarn installBuild the project:
yarn buildRun tests and generate code coverage:
yarn testRun linter:
yarn lint
Important | Keep in mind that JS sources are located in thesrc directories;lib directories contains transpiled code (created after runningyarn build)! |
If you use Visual Studio Code, you should install the following extensions:
The renderer module is originally based onnotebookjs 0.4.2 developed byJeremy Singer-Vine and distributed under theMIT License.
The mathExtractor module is based onmathjaxutils.js from theJupyter Notebook 6.0.1 distributed under theModified BSD License.
This project is licensed underMIT License.For the full text of the license, see theLICENSE file.
About
Convert Jupyter (IPython) Notebooks to static HTML
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.