File tree 3 files changed +67
-1
lines changed
components/dash-core-components
tests/integration/markdown
3 files changed +67
-1
lines changed Original file line number Diff line number Diff line change 2
2
All notable changes to `dash` will be documented in this file.
3
3
This project adheres to [Semantic Versioning](https://semver.org/).
4
4
5
+ ## [Unreleased]
6
+
7
+ ### Fixed
8
+
9
+ - [#2043](https://github.com/plotly/dash/pull/2043) Fix bug
10
+ [#2003](https://github.com/plotly/dash/issues/2003) in which
11
+ `dangerously_allow_html=True` + `mathjax=True` works in some cases, and in some cases not.
12
+
5
13
## [2.4.1] - 2022-05-11
6
14
7
15
### Fixed
Original file line number Diff line number Diff line change @@ -108,6 +108,20 @@ export default class DashMarkdown extends Component {
108
108
) }
109
109
/>
110
110
) ,
111
+ dashMathjax : props => (
112
+ < Math tex = { props . value } inline = { props . inline } />
113
+ ) ,
114
+ } ;
115
+
116
+ const regexMath = value => {
117
+ const newValue = value . replace (
118
+ / ( \$ { 1 , 2 } ) ( (?: \\ .| [ ^ $ ] ) + ) \1/ g,
119
+ function ( m , tag , src ) {
120
+ const inline = tag . length === 1 || src . indexOf ( '\n' ) === - 1 ;
121
+ return `<dashMathjax value='${ src } ' inline='${ inline } '/>` ;
122
+ }
123
+ ) ;
124
+ return newValue ;
111
125
} ;
112
126
113
127
return (
@@ -151,7 +165,11 @@ export default class DashMarkdown extends Component {
151
165
props . value
152
166
) : (
153
167
< JsxParser
154
- jsx = { props . value }
168
+ jsx = {
169
+ mathjax
170
+ ? regexMath ( props . value )
171
+ : props . value
172
+ }
155
173
components = { componentTransforms }
156
174
renderInWrapper = { false }
157
175
/>
Original file line number Diff line number Diff line change @@ -388,3 +388,43 @@ def test_mkdw009_target_blank_links(dash_dcc):
388
388
dash_dcc .find_element ("a" ).click ()
389
389
390
390
until (lambda : len (dash_dcc .driver .window_handles ) == 2 , timeout = 1 )
391
+
392
+
393
+ def test_mkdw010_mathjax_with_html (dash_dcc ):
394
+
395
+ app = Dash (__name__ )
396
+
397
+ CONTENT = [
398
+ """
399
+ <details>
400
+ <summary>Topic</summary>
401
+ Some details
402
+ </details>
403
+
404
+ $E = mc^2$
405
+ """ ,
406
+ """
407
+ <p>Some paragraph</p>
408
+
409
+ $E = mc^2$
410
+ """ ,
411
+ """
412
+ <p>Some paragraph</p>
413
+ $E = mc^2$
414
+ """ ,
415
+ """
416
+ <p>Some paragraph</p> $E = mc^2$
417
+ """ ,
418
+ """
419
+ <p>Some paragraph with $E = mc^2$ inline math</p>
420
+ """ ,
421
+ ]
422
+
423
+ app .layout = html .Div (
424
+ [dcc .Markdown (c , dangerously_allow_html = True , mathjax = True ) for c in CONTENT ]
425
+ )
426
+
427
+ dash_dcc .start_server (app )
428
+
429
+ dash_dcc .wait_for_element (".MathJax" )
430
+ assert len (dash_dcc .find_elements ((".MathJax" ))) == len (CONTENT )
You can’t perform that action at this time.
0 commit comments