diff --git a/CHANGELOG.md b/CHANGELOG.md index f70481f827..de45fb014f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to `dash` will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [Unreleased] + +### Fixed + +- [#2043](https://github.com/plotly/dash/pull/2043) Fix bug +[#2003](https://github.com/plotly/dash/issues/2003) in which +`dangerously_allow_html=True` + `mathjax=True` works in some cases, and in some cases not. + ## [2.4.1] - 2022-05-11 ### Fixed diff --git a/components/dash-core-components/src/fragments/Markdown.react.js b/components/dash-core-components/src/fragments/Markdown.react.js index dcd3fa8d14..420bcb3387 100644 --- a/components/dash-core-components/src/fragments/Markdown.react.js +++ b/components/dash-core-components/src/fragments/Markdown.react.js @@ -108,6 +108,20 @@ export default class DashMarkdown extends Component { )} /> ), + dashMathjax: props => ( + + ), + }; + + const regexMath = value => { + const newValue = value.replace( + /(\${1,2})((?:\\.|[^$])+)\1/g, + function (m, tag, src) { + const inline = tag.length === 1 || src.indexOf('\n') === -1; + return ``; + } + ); + return newValue; }; return ( @@ -151,7 +165,11 @@ export default class DashMarkdown extends Component { props.value ) : ( diff --git a/components/dash-core-components/tests/integration/markdown/test_markdown.py b/components/dash-core-components/tests/integration/markdown/test_markdown.py index bd4443ef55..786347cd5f 100644 --- a/components/dash-core-components/tests/integration/markdown/test_markdown.py +++ b/components/dash-core-components/tests/integration/markdown/test_markdown.py @@ -388,3 +388,43 @@ def test_mkdw009_target_blank_links(dash_dcc): dash_dcc.find_element("a").click() until(lambda: len(dash_dcc.driver.window_handles) == 2, timeout=1) + + +def test_mkdw010_mathjax_with_html(dash_dcc): + + app = Dash(__name__) + + CONTENT = [ + """ +
+ Topic + Some details +
+ + $E = mc^2$ + """, + """ +

Some paragraph

+ + $E = mc^2$ + """, + """ +

Some paragraph

+ $E = mc^2$ + """, + """ +

Some paragraph

$E = mc^2$ + """, + """ +

Some paragraph with $E = mc^2$ inline math

+ """, + ] + + app.layout = html.Div( + [dcc.Markdown(c, dangerously_allow_html=True, mathjax=True) for c in CONTENT] + ) + + dash_dcc.start_server(app) + + dash_dcc.wait_for_element(".MathJax") + assert len(dash_dcc.find_elements((".MathJax"))) == len(CONTENT)