This repository was archived by the owner on Nov 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (62 loc) · 1.83 KB
/
index.js
File metadata and controls
70 lines (62 loc) · 1.83 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const GitBook = require('gitbook-core');
const { React } = GitBook;
/**
* Math block when using SVG mode.
* @type {ReactClass}
*/
const MathJaxSVG = React.createClass({
propTypes: {
inline: React.PropTypes.bool.isRequired,
filename: React.PropTypes.string.isRequired
},
render() {
const { inline, filename } = this.props;
const img = <GitBook.Image src={filename} />;
if (inline) {
return img;
} else {
return (
<div className="MathJaxBlock-MathJaxSVG">
{img}
</div>
);
}
}
});
/**
* Math templating block.
* @type {ReactClass}
*/
const MathJaxBlock = React.createClass({
propTypes: {
isSVG: React.PropTypes.bool.isRequired,
inline: React.PropTypes.bool,
content: React.PropTypes.string,
filename: React.PropTypes.string
},
render() {
const { isSVG, inline, content, filename } = this.props;
return (
<span className="MathJaxBlock">
<GitBook.ImportCSS href="gitbook/mathjax/mathjax.css" />
{ isSVG ?
null
:
<GitBook.ImportScript src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML" />
}
{ isSVG ?
<MathJaxSVG filename={filename} inline={inline} />
:
<span>
<script type={`math/tex; ${inline ? '' : 'mode=display'}`}>{content}</script>
</span>
}
</span>
);
}
});
module.exports = GitBook.createPlugin({
activate: (dispatch, getState, { Components }) => {
dispatch(Components.registerComponent(MathJaxBlock, { role: 'block:math' }));
}
});