Installations
npm install notebookjs
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
21.7.1
NPM Version
10.5.0
Score
53.1
Supply Chain
95.2
Quality
78
Maintenance
100
Vulnerability
98.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (99.54%)
Makefile (0.46%)
Developer
jsvine
Download Statistics
Total Downloads
64,208
Last Day
36
Last Week
486
Last Month
2,042
Last Year
15,954
GitHub Statistics
280 Stars
107 Commits
47 Forks
12 Watching
4 Branches
5 Contributors
Bundle Size
2.48 MB
Minified
608.21 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.8.3
Package Id
notebookjs@0.8.3
Unpacked Size
27.85 kB
Size
8.04 kB
File Count
7
NPM Version
10.5.0
Node Version
21.7.1
Publised On
18 Aug 2024
Total Downloads
Cumulative downloads
Total Downloads
64,208
Last day
-65.7%
36
Compared to previous day
Last week
-9.5%
486
Compared to previous week
Last month
50.4%
2,042
Compared to previous month
Last year
110.1%
15,954
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
notebook.js v0.8.3
Notebook.js parses raw Jupyter/IPython notebooks, and lets you render them as HTML. See a working demo here.
Usage
Notebook.js works in the browser and in Node.js. Usage is fairly straightforward.
Browser Usage
First, provide access to nb
via a script tag:
1<script src="notebook.js"></script>
Then parse, render, and (perhaps) append:
var notebook = nb.parse(JSON.parse(raw_ipynb_json_string));
var rendered = notebook.render();
document.body.appendChild(rendered);
Node.js Usage
To install:
1npm install notebookjs
Then parse, render, and write:
1var fs = require("fs"); 2var nb = require("notebookjs"); 3var ipynb = JSON.parse(fs.readFileSync("path/to/notebook.ipynb")); 4var notebook = nb.parse(ipynb); 5console.log(notebook.render().outerHTML);
Markdown and ANSI-coloring
On Node.js, notebook.js uses marked for Markdown rendering, and ansi_up for ANSI-coloring.
The browser-based version does not, however, ship with those libraries, so you must <script>
-include or require
them before initializing notebook.js.
To support other Markdown or ANSI-coloring engines, set nb.markdown
and/or nb.ansi
to functions that accept raw text and return rendered text.
HTML and Markdown Sanitization
On Node.js, notebook.js runs all HTML and Markdown outputs through DOMPurify. The browser-based version, however, does not ship with this library; to enable the default behavior, you must <script>
-include or require
it before initializing notebook.js.
Alternative sanitizers can be passed by setting nb.sanitizer
to a function that accepts a raw HTML string and returns a sanitized version. (To disable sanitization, set nb.sanitizer = function (x) { return x; };
.)
Code-Highlighting
Notebook.js plays well with code-highlighting libraries. See NBPreview for an example of how to add support for your preferred highlighter. However, if you wish to inject your own highlighting, you can install a custom highlighter function by adding it under the highlighter
name in an notebookjs
instance. For instance, here is an implementation which colorizes languages using Prismjs during page generation for a static site:
1var Prism = require('prismjs'); 2 3var highlighter = function(code, lang) { 4 if (typeof lang === 'undefined') lang = 'markup'; 5 6 if (!Prism.languages.hasOwnProperty(lang)) { 7 try { 8 require('prismjs/components/prism-' + lang + '.js'); 9 } catch (e) { 10 console.warn('** failed to load Prism lang: ' + lang); 11 Prism.languages[lang] = false; 12 } 13 } 14 15 return Prism.languages[lang] ? Prism.highlight(code, Prism.languages[lang]) : code; 16}; 17 18var nb = require("notebookjs"); 19nb.highlighter = function(text, pre, code, lang) { 20 var language = lang || 'text'; 21 pre.className = 'language-' + language; 22 if (typeof code != 'undefined') { 23 code.className = 'language-' + language; 24 } 25 return highlighter(text, language); 26 };
A highlighter
function takes up to four arguments:
text
-- text of the cell to highlightpre
-- the DOM<pre>
node that holds the cellcode
-- the DOM<code>
node that holds the cell (ifundefined
then text is not code)lang
-- the language of the code in the cell (ifundefined
then text is not code)
The function should at least return the original text
value if it cannot perform any highlighting.
MathJax / LaTeX / KaTeX
Notebook.js currently doesn't support all of MathJax's syntaxes (MathML, AsciiMath, LaTeX). In the browser, however, it does support a significant subset of LaTeX via KaTeX. To enable this functionality, the webpage must have the following JavaScript and CSS libraries (or their equivalents, from other sources) loaded:
https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.12.0/katex.min.js
https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.12.0/contrib/auto-render.min.js
https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.12.0/katex.min.css
- KaTeX fonts
JavaScript Support
JavaScript in notebooks is not executed by default, because it opens the door for XSS attacks when using untrusted notebooks.
If you want to enable to run JavaScript set the executeJavaScript
option to true.
var nb = require("notebookjs");
// Run the JavaScript in notebook. Ensure you only use this for trusted notebooks
nb.executeJavaScript = true;
var notebook = nb.parse(ipynb);
Styling Rendered Notebooks
The HTML rendered by notebook.js (intentionally) does not contain any styling. But each key element has fairly straightfoward CSS classes that make styling your notebooks a cinch. See nbpreview
's stylesheet for an example implementation.
Thanks
Many thanks to the following users for catching bugs, fixing typos, and proposing useful features:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE.txt:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-gx9m-whjm-85jf
- Warn: Project is vulnerable to: GHSA-mmhx-hmjr-r674
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Reason
Found 8/17 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 21 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to notebookjs
@oraichain/notebookjs
Parse and render Jupyter/IPython notebooks.
babel-plugin-notebookjs
Hoist all the ExpressionStatement's values as an array, returned from an exported factory function
notebookjs-katex
Process embedded math expressions in IPython Markdown cells.
@openbayes/notebookjs
Parse and render Jupyter/IPython notebooks.