Skip to content

Commit 31e1a6e

Browse files
author
Hamada Gasmallah
committed
fix: make sure to load mathjax script if not loaded
1 parent 16ef91d commit 31e1a6e

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "backstage-plugin-techdocs-addon-mathjax",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"main": "src/index.ts",
55
"types": "src/index.ts",
66
"license": "MIT",

src/Mathjax/Mathjax.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
import { useEffect } from 'react';
22

3-
export const MathjaxAddon = () => {
4-
useEffect(()=>{
3+
function runTypeSet(){
54
if (typeof (<any>window)?.MathJax !== "undefined"){
5+
console.log("MathJax was found and typeset is called!");
66
(<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);
725
};
826

927
}, []);

0 commit comments

Comments
 (0)