Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Allow HTML content in Markdown cells #915

Closed
mjanschek opened this issue Jun 21, 2021 · 4 comments · Fixed by #916
Closed

Allow HTML content in Markdown cells #915

mjanschek opened this issue Jun 21, 2021 · 4 comments · Fixed by #916

Comments

@mjanschek
Copy link

Context

dash                      1.20.0
dash-bootstrap-components 0.12.2
dash-core-components      1.16.0
dash-html-components      1.1.3 
dash-renderer             1.9.1 
dash-table                4.11.3

Describe the bug

I am not sure, if this is a bug or intended behaviour.
A Datatable column that presents Markdown can't render html snippets. In this case, I try to include an icon from the bootstrap font.

Expected behavior

A Data Table that present Markdown should be able to render html code, as it's encouraged by Markdown guidelines. If I directly edit the websites html, the icon can be displayed. So the font is included correctly.

Minimal example

app.py

import dash
import dash_table

bs_icons = {
    "href": "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css",
    "rel": "stylesheet",
    "crossorigin": "anonymous",
}

app = dash.Dash(__name__, external_stylesheets=[bs_icons])

app.layout = dash_table.DataTable(
    id='table',
    columns=[{"name": "Alarm", "id": "html", "presentation": "markdown"}],
    data=[{"html": '<i class="bi bi-alarm"></i>'}],
)

if __name__ == '__main__':
    app.run_server(debug=True)

Screenshots
Original Table
image
Edited Table (wanted result)
image

@mjanschek mjanschek changed the title [BUG] dash_table : [BUG] dash_table: Can't parse html snippets Jun 21, 2021
@mjanschek mjanschek changed the title [BUG] dash_table: Can't parse html snippets [BUG] dash_table: Markdown column can't parse html element Jun 21, 2021
@alexcjohnson alexcjohnson transferred this issue from plotly/dash Jun 22, 2021
@alexcjohnson alexcjohnson changed the title [BUG] dash_table: Markdown column can't parse html element Allow HTML content in Markdown cells Jun 22, 2021
@alexcjohnson
Copy link
Collaborator

(moved to the table repo and recast as a feature request)

Dash-table uses Remarkable for its markdown, and by default Remarkable disables HTML input. I presume this is for security reasons, as untrusted HTML input often creates XSS vulnerabilities. We would, however, be comfortable exposing the ability to enable HTML input on an opt-in basis. This may be as simple as adding html to the markdown_options prop and the corresponding interface, if someone would like to create a PR to try it!

@mjanschek
Copy link
Author

@alexcjohnson thank you so much for considering this!

@AnnMarieW
Copy link
Contributor

Hey @alexcjohnson - Thanks for the pointers - that worked great! 🍰
I'll do a PR.

image

import dash
import dash_table

bs_icons = {
    "href": "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css",
    "rel": "stylesheet",
    "crossorigin": "anonymous",
}

app = dash.Dash(__name__, external_stylesheets=[bs_icons])

app.layout = dash_table.DataTable(
    id="table",
    columns=[{"name": "Alarm", "id": "html", "presentation": "markdown"}],
    data=[{"html": '<i class="bi bi-alarm"></i>'}, {"html": '<i class="bi bi-emoji-sunglasses"></i>'}],
    markdown_options={"html": True},
)

if __name__ == "__main__":
    app.run_server(debug=True)


@prhbrt
Copy link

prhbrt commented Jul 15, 2022

Quick note, also link_target as discussed here works now.

markdown_options={"html": True, "link_target": "_self"},

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants