Skip to content

Commit c08292f

Browse files
committed
docs: add JSON.parse usage example for string ipynb data #63
1 parent e41c533 commit c08292f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,37 @@ $ npm install --save react-ipynb-renderer-katex
5454
# Usage
5555
Just pass an ipynb json object to `IpynbRenderer` component.
5656

57+
## Using ipynb as a string
58+
If you have an ipynb file as a string, you can parse it using `JSON.parse()`:
59+
60+
```jsx
61+
import { IpynbRenderer } from "react-ipynb-renderer";
62+
63+
// Jupyter theme
64+
import "react-ipynb-renderer/dist/styles/monokai.css";
65+
66+
export const Component = () => {
67+
const ipynbString = `{
68+
"cells": [
69+
{
70+
"cell_type": "markdown",
71+
"metadata": {},
72+
"source": ["# Hello World"]
73+
}
74+
],
75+
"metadata": {},
76+
"nbformat": 4,
77+
"nbformat_minor": 4
78+
}`;
79+
80+
const ipynb = JSON.parse(ipynbString);
81+
82+
return (
83+
<IpynbRenderer ipynb={ipynb} />
84+
);
85+
};
86+
```
87+
5788
## Simplest example
5889

5990
### Using react-ipynb-renderer

0 commit comments

Comments
 (0)