Skip to content

Commit

Permalink
Enable MathJax in dcc.Markdown (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer authored Nov 23, 2022
1 parent a47d14a commit c78ae45
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- [#648](https://github.com/equinor/webviz-config/pull/648) - Allow `blob:` in `script-src` CSP in order to enable web worker usage in Dash components.
- [#652](https://github.com/equinor/webviz-config/pull/652) - Enabled support for LaTeX math/equations in markdown.

### Added
- [#644](https://github.com/equinor/webviz-config/pull/644) - Added option to download tables in `DataTable` and `PivotTable`.
Expand Down
1 change: 1 addition & 0 deletions examples/basic_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ layout:
title: My banner image
- Webviz created from configuration file.
- Some other text, potentially with strange letters like Åre, Smørbukk Sør.
- And even math like $e^{\pi i} + 1 = 0$.

- page: Markdown example
content:
Expand Down
12 changes: 12 additions & 0 deletions examples/example-markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
Hi from a Markdown text file containing Norwegian letters (æ ø å), some
**bold** letters, _italic_ letters. _You can also **combine** them._

You can also add (potential multi-line) equations as illustrated here with the Maxwell equations,
$$
\begin{aligned}
\nabla \cdot \mathbf{E} &= \frac {\rho} {\varepsilon_0} \\\\
\nabla \cdot \mathbf{B} &= 0 \\\\
\nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}} {\partial t} \\\\
\nabla \times \mathbf{B} &= \mu_0\left(\mathbf{J} + \varepsilon_0 \frac{\partial \mathbf{E}} {\partial t} \right)
\end{aligned}
$$
You can also add inline math where you e.g. describe the different parameters that goes into
the equations, like $\varepsilon_0$ being permittivity of free space.

---

Horizontal line splitting two paragraphs.
Expand Down
5 changes: 4 additions & 1 deletion webviz_config/generic_plugins/_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ def add_webvizstore(self) -> List[tuple]:
@property
def layout(self) -> dcc.Markdown:
return dcc.Markdown(
self.html, dangerously_allow_html=True, className="webviz-config-markdown"
self.html,
dangerously_allow_html=True,
mathjax=True,
className="webviz-config-markdown",
)


Expand Down
2 changes: 1 addition & 1 deletion webviz_config/templates/webviz_template.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ else:
page_settings["{{page.id}}"] = []
{% for content_item in page.content -%}
{% if content_item is string %}
page_plugins["{{page.id}}"].append(wcc.WebvizPluginWrapper(id=f"text-{count_text_plugins}", views=[], initiallyActiveViewId="", name="Text", children=[dcc.Markdown(r"""{{ content_item }}""")]))
page_plugins["{{page.id}}"].append(wcc.WebvizPluginWrapper(id=f"text-{count_text_plugins}", views=[], initiallyActiveViewId="", name="Text", children=[dcc.Markdown(r"""{{ content_item }}""", mathjax=True)]))
count_text_plugins += 1
{% else %}
plugin = webviz_config.plugins.{{ content_item._call_signature[0] }}
Expand Down

0 comments on commit c78ae45

Please sign in to comment.