Skip to content

Commit a39c43a

Browse files
committed
Use a default font size when it can't be computed directly (e.g., the element is not in an active DOM). (mathjax/MathJax#3458)
1 parent 27c47f3 commit a39c43a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ts/adaptors/HTMLAdaptor.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ export class HTMLAdaptor<
199199
extends AbstractDOMAdaptor<N, T, D>
200200
implements MinHTMLAdaptor<N, T, D>
201201
{
202+
203+
/**
204+
* The font size to use when it can't be measured (e.g., the element
205+
* isn't in the DOM).
206+
*/
207+
public static DEFAULT_FONT_SIZE = 16;
208+
202209
/**
203210
* The HTML adaptor can measure DOM node sizes
204211
*/
@@ -588,7 +595,10 @@ export class HTMLAdaptor<
588595
*/
589596
public fontSize(node: N) {
590597
const style = this.window.getComputedStyle(node);
591-
return parseFloat(style.fontSize);
598+
return parseFloat(
599+
style.fontSize ||
600+
String((this.constructor as typeof HTMLAdaptor).DEFAULT_FONT_SIZE)
601+
);
592602
}
593603

594604
/**

0 commit comments

Comments
 (0)