Skip to content

Commit 9da5928

Browse files
authored
Handle mathjax arg when passed to Kaleido constructor (#320)
* pop 'mathjax' arg from kwargs in Kaleido constructor, and pass to PageGenerator() * test passing different mathjax url to calc_fig_sync()
1 parent 154cd0d commit 9da5928

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/py/kaleido/kaleido.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def __init__(self, *args, **kwargs): # noqa: D417 no args/kwargs in description
106106
self._height = kwargs.pop("height", None)
107107
self._width = kwargs.pop("width", None)
108108
self._stepper = kwargs.pop("stepper", False)
109+
self._mathjax = kwargs.pop("mathjax", None)
109110
if not kwargs.get("headless", True) and (self._height or self._width):
110111
warnings.warn(
111112
"Height and Width can only be used if headless=True, "
@@ -135,7 +136,7 @@ def __init__(self, *args, **kwargs): # noqa: D417 no args/kwargs in description
135136
index = self.tmp_dir.path / "index.html"
136137
self._index = index.as_uri()
137138
if not page:
138-
page = PageGenerator()
139+
page = PageGenerator(mathjax=self._mathjax)
139140
page.generate_index(index)
140141

141142
async def _conform_tabs(self, tabs=None) -> None:

src/py/tests/test_calc_fig.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ async def test_calc_fig():
2222
img_awaited = await kaleido.calc_fig(fig)
2323
assert isinstance(img_awaited, bytes)
2424

25-
img_sync = kaleido.calc_fig_sync(fig)
25+
# Make sure passing `mathjax` argument via `kopts` works properly
26+
img_sync = kaleido.calc_fig_sync(
27+
fig,
28+
kopts={"mathjax": "https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-svg.js"},
29+
)
2630
assert isinstance(img_sync, bytes)
2731

2832
img_from_dict = kaleido.calc_fig_sync(fig.to_dict())

0 commit comments

Comments
 (0)