diff --git a/src/py/kaleido/_page_generator.py b/src/py/kaleido/_page_generator.py index cda04aff..fe5ad505 100644 --- a/src/py/kaleido/_page_generator.py +++ b/src/py/kaleido/_page_generator.py @@ -8,7 +8,10 @@ _logger = logistro.getLogger(__name__) DEFAULT_PLOTLY = "https://cdn.plot.ly/plotly-2.35.2.js" -DEFAULT_MATHJAX = "https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-svg.js" +DEFAULT_MATHJAX = ( + "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" + "?config=TeX-AMS-MML_SVG" +) KJS_PATH = Path(__file__).resolve().parent / "vendor" / "kaleido_scopes.js" @@ -46,7 +49,7 @@ class PageGenerator: footer = f""" - + """ """The footer is the HTML that always goes on the bottom. Rarely needs changing.""" @@ -67,6 +70,12 @@ def __init__(self, *, plotly=None, mathjax=None, others=None, force_cdn=False): """ self._scripts = [] + if mathjax is not False: + if not mathjax: + mathjax = DEFAULT_MATHJAX + else: + _ensure_path(mathjax) + self._scripts.append(mathjax) if force_cdn: plotly = (DEFAULT_PLOTLY, "utf-8") elif not plotly: @@ -97,12 +106,6 @@ def __init__(self, *, plotly=None, mathjax=None, others=None, force_cdn=False): plotly = (plotly, "utf-8") _logger.debug(f"Plotly script: {plotly}") self._scripts.append(plotly) - if mathjax is not False: - if not mathjax: - mathjax = DEFAULT_MATHJAX - else: - _ensure_path(mathjax) - self._scripts.append(mathjax) if others: for o in others: _ensure_path(o) diff --git a/src/py/kaleido/vendor/index.html b/src/py/kaleido/vendor/index.html deleted file mode 100644 index 91b9922a..00000000 --- a/src/py/kaleido/vendor/index.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - Kaleido-fier - - - - - - - - diff --git a/src/py/tests/test_page_generator.py b/src/py/tests/test_page_generator.py index ab5082d0..ad72bf52 100644 --- a/src/py/tests/test_page_generator.py +++ b/src/py/tests/test_page_generator.py @@ -6,13 +6,18 @@ import pytest from kaleido import PageGenerator +from kaleido._page_generator import DEFAULT_MATHJAX, DEFAULT_PLOTLY # allows to create a browser pool for tests pytestmark = pytest.mark.asyncio(loop_scope="function") _logger = logistro.getLogger(__name__) -no_imports_result_re = re.compile(r""" +_re_default_mathjax = re.escape(DEFAULT_MATHJAX) +_re_default_plotly = re.escape(DEFAULT_PLOTLY) + +no_imports_result_raw = ( + r''' @@ -25,15 +30,22 @@ MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\) - - + + - + -""") # noqa: E501 line too long +""" +) +no_imports_result_re = re.compile(no_imports_result_raw) -all_defaults_re = re.compile(r""" +all_defaults_re = re.compile( + r''' @@ -46,15 +58,19 @@ MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\) + - - + -""") +""", +) -with_plot_result_re = re.compile(r""" +with_plot_result_re = re.compile( + r''' @@ -67,13 +83,16 @@ MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\) + - - + -""") +""", +) without_math_result_re = re.compile(r""" @@ -91,11 +110,11 @@ - + """) -with_others_result_re = re.compile(r""" +with_others_result_raw = r""" @@ -108,15 +127,16 @@ MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\) - + - + -""") +""" +with_others_result_re = re.compile(with_others_result_raw) @pytest.mark.order(1) @@ -136,7 +156,11 @@ async def test_page_generator(): "in the main group.", ) no_imports = PageGenerator().generate_index() - assert no_imports_result_re.findall(no_imports) + assert no_imports_result_re.findall(no_imports), ( + f"{len(no_imports_result_raw)}: {no_imports_result_raw}" + "\n" + f"{len(no_imports)}: {no_imports}" + ) sys.path = old_path # this imports plotly so above test must have already been done @@ -157,7 +181,11 @@ async def test_page_generator(): mathjax="https://with_mathjax", others=["https://1", "https://2"], ).generate_index() - assert with_others_result_re.findall(with_others) + assert with_others_result_re.findall(with_others), ( + f"{len(with_others_result_raw)}: {with_others_result_raw}" + "\n" + f"{len(with_others)}: {with_others}" + ) # test others