forked from calvinkei/react-native-mathjax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (40 loc) · 1.06 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
import React from 'react';
import _ from 'lodash';
import AutoHeightWebView from 'react-native-autoheight-webview';
const defaultOptions = {
messageStyle: 'none',
extensions: [ 'tex2jax.js' ],
jax: [ 'input/TeX', 'output/HTML-CSS' ],
tex2jax: {
inlineMath: [ ['$','$'], ['\\(','\\)'] ],
displayMath: [ ['$$','$$'], ['\\[','\\]'] ],
processEscapes: true,
},
TeX: {
extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js']
}
};
class MathJax extends React.Component {
wrapMathjax(content) {
const options = JSON.stringify(
_.merge(defaultOptions, this.props.mathJaxOptions)
);
return `
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script type="text/x-mathjax-config">
MathJax.Hub.Config(${options});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
${content}
`;
}
render() {
return (
<AutoHeightWebView
source={{ html: this.wrapMathjax(this.props.html) }}
{...this.props}
/>
);
}
}
export default MathJax;