forked from rmoorman/react-jupyter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (37 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React, { Component } from 'react'
import PropTypes from 'prop-types';
import Notebook from './Notebook'
import './jupyter-default.css'
const asyncLoadMathjax = () => {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.onload = () => {}
script.src = 'https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
head.appendChild(script);
}
class JuptyerRenderer extends Component {
static propTypes = {
notebook: PropTypes.object.isRequired,
defaultStyle: PropTypes.bool,
loadMathjax: PropTypes.bool,
showCode: PropTypes.bool
}
componentDidMount() {
const { loadMathjax = true } = this.props
if (loadMathjax) {
asyncLoadMathjax()
}
}
render() {
const { notebook, defaultStyle = true, showCode = true } = this.props
let cls = defaultStyle ? "jupyter-default" : "jupyter"
if (showCode) cls += " showCode"
return (
<div className={cls}>
<Notebook raw={notebook} showCode={showCode}/>
</div>
)
}
}
export default JuptyerRenderer