Skip to content

Commit 657c4b7

Browse files
authored
Merge branch 'plotly:dev' into debug_env
2 parents 0f04c19 + 1e57fb2 commit 657c4b7

File tree

9 files changed

+95
-9
lines changed

9 files changed

+95
-9
lines changed

@plotly/dash-generator-test-component-typescript/generator.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ function getMetadata() {
1212
'""', // reserved keywords
1313
path.join(__dirname, 'src', 'components')
1414
],
15-
// To debug `meta-ts.js` using pycharm debugger:
16-
// comment `env` and add `MODULES_PATH=./node_modules`
17-
// in the run config environment variables.
1815
{
19-
env: {MODULES_PATH: path.resolve(__dirname, './node_modules')},
16+
env: {MODULES_PATH: path.resolve(__dirname, './node_modules'), ...process.env},
2017
cwd: __dirname
2118
}
2219
);
@@ -245,4 +242,9 @@ describe('Test Typescript component metadata generation', () => {
245242
expect(R.path(['StandardComponent'], metadata)).toBeDefined();
246243
});
247244
});
245+
describe('Test namespace props', () => {
246+
test('Component with picked boolean prop', () => {
247+
expect(R.path(['WrappedHTML', "props", "autoFocus", "type", "name"], metadata)).toBe("bool");
248+
})
249+
})
248250
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import {WrappedHTMLProps} from '../props';
3+
4+
/**
5+
* Component docstring
6+
*/
7+
const WrappedHTML = (props: WrappedHTMLProps) => {
8+
return null;
9+
};
10+
11+
export default WrappedHTML;

@plotly/dash-generator-test-component-typescript/src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import TypeScriptComponent from './components/TypeScriptComponent';
22
import TypeScriptClassComponent from './components/TypeScriptClassComponent';
33
import MemoTypeScriptComponent from './components/MemoTypeScriptComponent';
44
import StandardComponent from './components/StandardComponent.react';
5+
import WrappedHTML from './components/WrappedHTML';
56

67
export {
78
TypeScriptComponent,
89
TypeScriptClassComponent,
910
MemoTypeScriptComponent,
10-
StandardComponent
11+
StandardComponent,
12+
WrappedHTML,
1113
};

@plotly/dash-generator-test-component-typescript/src/props.ts

+5
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ export type TypescriptComponentProps = {
3636
className?: string;
3737
style?: any;
3838
};
39+
40+
export type WrappedHTMLProps = {
41+
children?: React.ReactNode;
42+
id?: string;
43+
} & Pick<React.ButtonHTMLAttributes<any>, 'autoFocus'>

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

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+
513
## [2.4.1] - 2022-05-11
614

715
### Fixed

components/dash-core-components/src/fragments/Markdown.react.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ export default class DashMarkdown extends Component {
108108
)}
109109
/>
110110
),
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;
111125
};
112126

113127
return (
@@ -151,7 +165,11 @@ export default class DashMarkdown extends Component {
151165
props.value
152166
) : (
153167
<JsxParser
154-
jsx={props.value}
168+
jsx={
169+
mathjax
170+
? regexMath(props.value)
171+
: props.value
172+
}
155173
components={componentTransforms}
156174
renderInWrapper={false}
157175
/>

components/dash-core-components/tests/integration/markdown/test_markdown.py

+40
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,43 @@ def test_mkdw009_target_blank_links(dash_dcc):
388388
dash_dcc.find_element("a").click()
389389

390390
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)

dash/_callback_context.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def args_grouping(self):
127127
args_grouping is a dict of the inputs used with flexible callback signatures. The keys are the variable names
128128
and the values are dictionaries containing:
129129
- “id”: (string or dict) the component id. If it’s a pattern matching id, it will be a dict.
130-
- “id_str”: (str) for pattern matching ids, it’s the strigified dict id with no white spaces.
130+
- “id_str”: (str) for pattern matching ids, it’s the stringified dict id with no white spaces.
131131
- “property”: (str) The component property used in the callback.
132132
- “value”: the value of the component property at the time the callback was fired.
133133
- “triggered”: (bool)Whether this input triggered the callback.

dash/extract-meta.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ if (!src.length) {
3737
}
3838

3939
if (fs.existsSync('tsconfig.json')) {
40-
tsconfig = JSON.parse(fs.readFileSync('tsconfig.json'));
40+
tsconfig = JSON.parse(fs.readFileSync('tsconfig.json')).compilerOptions;
4141
}
4242

4343
let failedBuild = false;
@@ -180,7 +180,7 @@ function gatherComponents(sources, components = {}) {
180180
return components;
181181
}
182182

183-
const program = ts.createProgram(filepaths, tsconfig);
183+
const program = ts.createProgram(filepaths, {...tsconfig, esModuleInterop: true});
184184
const checker = program.getTypeChecker();
185185

186186
const coerceValue = t => {

0 commit comments

Comments
 (0)