File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " backstage-plugin-techdocs-addon-mathjax" ,
3
- "version" : " 0.0.1 " ,
3
+ "version" : " 0.0.2 " ,
4
4
"main" : " src/index.ts" ,
5
5
"types" : " src/index.ts" ,
6
6
"license" : " MIT" ,
Original file line number Diff line number Diff line change 1
1
import { useEffect } from 'react' ;
2
2
3
- export const MathjaxAddon = ( ) => {
4
- useEffect ( ( ) => {
3
+ function runTypeSet ( ) {
5
4
if ( typeof ( < any > window ) ?. MathJax !== "undefined" ) {
5
+ console . log ( "MathJax was found and typeset is called!" ) ;
6
6
( < any > window ) . MathJax . typeset ( ) ;
7
+ return true ;
8
+ }
9
+ return false ;
10
+ } ;
11
+
12
+
13
+ export const MathjaxAddon = ( ) => {
14
+ useEffect ( ( ) => {
15
+
16
+ if ( ! runTypeSet ( ) ) {
17
+ console . log ( "No MathJax was found, now loading!" ) ;
18
+ const script = document . createElement ( 'script' ) ;
19
+ script . src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js' ;
20
+ script . async = true ;
21
+ document . body . appendChild ( script ) ;
22
+ setTimeout ( ( ) => {
23
+ runTypeSet ( ) ;
24
+ } , 500 ) ;
7
25
} ;
8
26
9
27
} , [ ] ) ;
You can’t perform that action at this time.
0 commit comments