-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.js
44 lines (33 loc) · 979 Bytes
/
math.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
// @flow
/* eslint-env browser */
'use strict';
/* global preact, katex */
/* ::
type MathProps = {
math: string;
options?: KaTeXOptions,
};
*/
// See https://preactjs.com/guide/external-dom-mutations for an
// explanation.
class KaTeX extends preact.Component /* :: <MathProps, {}> */ {
componentDidMount() {
// eslint-disable-next-line react/prop-types
katex.render(this.props.math, this.base, this.props.options);
}
componentWillReceiveProps(nextProps /* : MathProps */) {
katex.render(nextProps.math, this.base, nextProps.options);
}
shouldComponentUpdate() {
return false;
}
render() {
return preact.h('span');
}
}
// eslint-disable-next-line no-unused-vars
const inlineMath = (math /* : string */) => preact.h(KaTeX, { math });
// eslint-disable-next-line no-unused-vars
const displayMath = (math /* : string */) =>
preact.h(KaTeX, { math, options: { displayMode: true } });
/* :: export { inlineMath, displayMath }; */