From 8b83f1ff74533ece50a8beca0dc95703a1934f2a Mon Sep 17 00:00:00 2001 From: nickmelnikov82 Date: Wed, 11 May 2022 12:20:56 +0300 Subject: [PATCH 1/3] Fix markdown mathjax in html. --- .../src/fragments/Markdown.react.js | 20 ++++++++++++++++++- .../integration/markdown/test_markdown.py | 17 ++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) 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..bdc7178496 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,20 @@ 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__) + + app.layout = html.Div( + dcc.Markdown( + "

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

", + dangerously_allow_html=True, + mathjax=True, + ) + ) + + dash_dcc.start_server(app) + + dash_dcc.wait_for_element(".MathJax") From 3e79e341e663db80d84deec00dd9f39004d5a057 Mon Sep 17 00:00:00 2001 From: nickmelnikov82 Date: Thu, 12 May 2022 11:09:53 +0300 Subject: [PATCH 2/3] Add additional failing cases to test. --- .../integration/markdown/test_markdown.py | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) 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 bdc7178496..786347cd5f 100644 --- a/components/dash-core-components/tests/integration/markdown/test_markdown.py +++ b/components/dash-core-components/tests/integration/markdown/test_markdown.py @@ -394,14 +394,37 @@ 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( - "

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

", - dangerously_allow_html=True, - mathjax=True, - ) + [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) From 93a392a4c65f5873fcb376e3fa7f3ce0a2e972f7 Mon Sep 17 00:00:00 2001 From: nickmelnikov82 Date: Thu, 12 May 2022 11:19:15 +0300 Subject: [PATCH 3/3] Added changelog entry. --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) 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