From 2ce8232f51865880b8100dff04f1ead32a256b75 Mon Sep 17 00:00:00 2001 From: Jochem Smit Date: Mon, 10 Jun 2024 12:23:06 +0200 Subject: [PATCH 1/4] feat: add mhchem katex extension mhchem package provides commands for typesetting chemical molecular formulae and equations --- solara/components/markdown.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/solara/components/markdown.py b/solara/components/markdown.py index 35eac7a28..8613e8046 100644 --- a/solara/components/markdown.py +++ b/solara/components/markdown.py @@ -92,6 +92,7 @@ def _markdown_template( await this.loadRequire(); this.mermaid = await this.loadMermaid(); this.mermaid.init(); + await this.loadMHchem(); this.latexSettings = { delimiters: [ {left: "$$", right: "$$", display: true}, @@ -157,6 +158,11 @@ def _markdown_template( async loadMermaid() { return (await this.import([`${this.getCdn()}/mermaid@10.8.0/dist/mermaid.min.js`]))[0] }, + async loadMHchem() { + await this.loadKatex(); + return (await this.import([`${this.getCdn()}/katex@0.16.9/dist/contrib/mhchem.min.js`]))[0]; + }, + import(dependencies) { return this.loadRequire().then( () => { From 4ced3598b002bc9c27f6ac1235163b716a4b032f Mon Sep 17 00:00:00 2001 From: Jochem Smit Date: Mon, 8 Jul 2024 15:04:05 +0200 Subject: [PATCH 2/4] move mhchem loading to loadKatexExt --- solara/components/markdown.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/solara/components/markdown.py b/solara/components/markdown.py index 8613e8046..808171212 100644 --- a/solara/components/markdown.py +++ b/solara/components/markdown.py @@ -92,7 +92,6 @@ def _markdown_template( await this.loadRequire(); this.mermaid = await this.loadMermaid(); this.mermaid.init(); - await this.loadMHchem(); this.latexSettings = { delimiters: [ {left: "$$", right: "$$", display: true}, @@ -153,16 +152,11 @@ def _markdown_template( }, async loadKatexExt() { this.loadKatex(); - return (await this.import([`${this.getCdn()}/katex@0.16.9/dist/contrib/auto-render.min.js`]))[0] + return (await this.import([`${this.getCdn()}/katex@0.16.9/dist/contrib/auto-render.min.js`, `${this.getCdn()}/katex@0.16.9/dist/contrib/mhchem.min.js`]))[0] }, async loadMermaid() { return (await this.import([`${this.getCdn()}/mermaid@10.8.0/dist/mermaid.min.js`]))[0] }, - async loadMHchem() { - await this.loadKatex(); - return (await this.import([`${this.getCdn()}/katex@0.16.9/dist/contrib/mhchem.min.js`]))[0]; - }, - import(dependencies) { return this.loadRequire().then( () => { From cd14ccf9e1c0c89b7c57c793e288127062d7bb6e Mon Sep 17 00:00:00 2001 From: Jochem Smit Date: Mon, 8 Jul 2024 15:08:39 +0200 Subject: [PATCH 3/4] style: split import over multiple lines --- solara/components/markdown.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/solara/components/markdown.py b/solara/components/markdown.py index 808171212..c0fd1b32b 100644 --- a/solara/components/markdown.py +++ b/solara/components/markdown.py @@ -152,7 +152,10 @@ def _markdown_template( }, async loadKatexExt() { this.loadKatex(); - return (await this.import([`${this.getCdn()}/katex@0.16.9/dist/contrib/auto-render.min.js`, `${this.getCdn()}/katex@0.16.9/dist/contrib/mhchem.min.js`]))[0] + return (await this.import([ + `${this.getCdn()}/katex@0.16.9/dist/contrib/auto-render.min.js`, + `${this.getCdn()}/katex@0.16.9/dist/contrib/mhchem.min.js` + ]))[0] }, async loadMermaid() { return (await this.import([`${this.getCdn()}/mermaid@10.8.0/dist/mermaid.min.js`]))[0] From 71b08463f0745b07873101c9c7d0d1891e495ac0 Mon Sep 17 00:00:00 2001 From: Jochem Smit Date: Mon, 8 Jul 2024 16:18:27 +0200 Subject: [PATCH 4/4] style: remove trailing whitespace --- solara/components/markdown.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solara/components/markdown.py b/solara/components/markdown.py index c0fd1b32b..b6233893a 100644 --- a/solara/components/markdown.py +++ b/solara/components/markdown.py @@ -153,7 +153,7 @@ def _markdown_template( async loadKatexExt() { this.loadKatex(); return (await this.import([ - `${this.getCdn()}/katex@0.16.9/dist/contrib/auto-render.min.js`, + `${this.getCdn()}/katex@0.16.9/dist/contrib/auto-render.min.js`, `${this.getCdn()}/katex@0.16.9/dist/contrib/mhchem.min.js` ]))[0] },