Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 0a4acf5

Browse files
authored
Merge pull request #916 from AnnMarieW/markdown-html
Allow HTML content in Markdown cells
2 parents d8f4e6c + a9c3981 commit 0a4acf5

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1010

1111

1212
### Added
13+
- [#916](https://github.com/plotly/dash-table/pull/916)
14+
- Added `html` option to `markdown_options` prop. This enables the use of html tags in markdown text.
15+
1316
- [#545](https://github.com/plotly/dash-table/issues/545)
1417
- Case insensitive filtering
1518
- New props: `filter_options` - to control case of all filters, `columns.filter_options` - to control filter case for each column

src/dash-table/components/Table/props.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export interface INumberLocale {
163163

164164
export interface IMarkdownOptions {
165165
link_target: '_blank' | '_parent' | '_self' | '_top' | string;
166+
html?: boolean;
166167
}
167168

168169
export type NumberFormat =

src/dash-table/dash/DataTable.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export const defaultProps = {
6767
},
6868

6969
markdown_options: {
70-
link_target: '_blank'
70+
link_target: '_blank',
71+
html: false
7172
},
7273

7374
tooltip: {},
@@ -483,7 +484,13 @@ export const propTypes = {
483484
link_target: PropTypes.oneOfType([
484485
PropTypes.string,
485486
PropTypes.oneOf(['_blank', '_parent', '_self', '_top'])
486-
]).isRequired
487+
]),
488+
/**
489+
* (default: False) If True, html may be used in markdown cells
490+
* Be careful enabling html if the content being rendered can come
491+
* from an untrusted user, as this may create an XSS vulnerability.
492+
*/
493+
html: PropTypes.bool
487494
}),
488495

489496
/**
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import dash
2+
from dash_table import DataTable
3+
4+
5+
def get_app(markdown_options):
6+
7+
app = dash.Dash(__name__)
8+
9+
props = dict(
10+
id="table",
11+
columns=[dict(name="a", id="a", type="text", presentation="markdown")],
12+
data=[dict(a="<h1>html h1 heading</h1>")],
13+
)
14+
15+
if markdown_options is not None:
16+
props["markdown_options"] = markdown_options
17+
18+
app.layout = DataTable(**props)
19+
20+
return app
21+
22+
23+
def test_tmdh001_html_not_allowed(test):
24+
test.start_server(get_app(None))
25+
26+
h1_elements = test.find_elements("h1")
27+
28+
assert len(h1_elements) == 0
29+
assert test.get_log_errors() == []
30+
31+
32+
def test_tmdh002_html_allowed(test):
33+
test.start_server(get_app(dict(html=True)))
34+
35+
h1_elements = test.find_elements("h1")
36+
37+
assert len(h1_elements) == 1
38+
assert test.get_log_errors() == []

0 commit comments

Comments
 (0)