File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -15,18 +15,28 @@ export async function renderMath() {
15
15
import ( /* webpackChunkName: "katex" */ 'katex/dist/katex.css' ) ,
16
16
] ) ;
17
17
18
+ const MAX_CHARS = 1000 ;
19
+ const MAX_SIZE = 25 ;
20
+ const MAX_EXPAND = 1000 ;
21
+
18
22
for ( const el of els ) {
19
23
const target = targetElement ( el ) ;
20
24
if ( target . hasAttribute ( 'data-render-done' ) ) continue ;
21
25
const source = el . textContent ;
26
+
27
+ if ( source . length > MAX_CHARS ) {
28
+ displayError ( target , new Error ( `Math source of ${ source . length } characters exceeds the maximum allowed length of ${ MAX_CHARS } .` ) ) ;
29
+ continue ;
30
+ }
31
+
22
32
const displayMode = el . classList . contains ( 'display' ) ;
23
33
const nodeName = displayMode ? 'p' : 'span' ;
24
34
25
35
try {
26
36
const tempEl = document . createElement ( nodeName ) ;
27
37
katex . render ( source , tempEl , {
28
- maxSize : 25 ,
29
- maxExpand : 50 ,
38
+ maxSize : MAX_SIZE ,
39
+ maxExpand : MAX_EXPAND ,
30
40
displayMode,
31
41
} ) ;
32
42
target . replaceWith ( tempEl ) ;
You can’t perform that action at this time.
0 commit comments