1.1.1 • Published 4 years ago

react-nbviewer v1.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

react-nbviewer

Render Jupyter Notebooks as React components.

NPM JavaScript Style Guide

Install

npm install --save react-nbviewer

Usage

import React from 'react'

import NbViewer from 'react-nbviewer'
import 'react-nbviewer/dist/index.css'

import Markdown from 'react-markdown'
import SyntaxHighlighter from 'react-syntax-highlighter'

<Nbviewer
  source="{.ipynb file content}"
  markdown={Markdown}
  code={SyntaxHighlighter} />

Importing react-nbviewer/dist/index.css is not required. You can style the component on your own. See src/index.css for details.

Options

NameTypeDescription
sourcestring or objectThe Jupyter Notebook source to parse.
markdownReactNode<{source: string}>(Optional) The React component to render Markdown. react-markdown is recommended.
codeReactNode<{language: string, children: string}>(Optional) The React component to highlight code blocks.

Complete example

Here's a more complete example which also renders math in Markdown cells:

import React from 'react'
import ReactDOM from 'react-dom'
import NbViewer from 'react-nbviewer'
import Markdown from 'react-markdown'
import MathPlugin from 'remark-math'
import TeX from '@matejmazur/react-katex'
import Highlighter from 'react-syntax-highlighter'
import 'react-nbviewer/dist/index.css'
import 'katex/dist/katex.min.css'

const MathMarkdown = (props) => {
  const renderers = {
    math: ({ value }) => <TeX block math={value} />,
    inlineMath: ({ value }) => <TeX math={value} />,
    code: props => <Highlighter language={props.language}>{props.value}</Highlighter>
  }
  return <Markdown renderers={renderers} plugins={[MathPlugin]} source={props.source} />
}

ReactDOM.render(
  <NbViewer source="{.ipynb file content}" markdown={MathMarkdown} code={Highlighter} />,
  document.getElementById('root')
)

License

MIT © chuangzhu

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0-1

4 years ago

1.0.0

4 years ago