did you ever figure out a solution to this?
I have a similar usecase where I’d like to invoke some simple HTML inside of the markdown block, and it’s impractical to close/reopen dcc.Markdown just to do that.
I wonder if this would cause an issue though with the desire to avoid ‘no raw html’?
I am also looking for ways to change style inside dcc.Markdown but that’s probably not available now. The code below can change the colour.
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div(dcc.Markdown('''Am I red yet?'''), style={'color':'red'})
app.run_server(debug=True)
Hi all,
I’m also bothered by how to partial use color use to emphasize words
The solution is quite simple: use html all round the children in the dcc.Markdown component with the argument dangerously_allow_html=True
Noted that it seems that dangerously_allow_html has some secure issues, but I’m not familiar with them
Here is the example:
from dash import dcc, html
import dash
app = dash.Dash(__name__)
app.layout = html.Div(
children=dcc.Markdown(
'''
<p style="margin: 0"> Hello, these some testing colorful words:</p>
<p style="margin: 0"> I am <span style="color: red">red</span>.</p>
<p style="margin: 0"> I am <span style="color: orange">orange</span>.</p>
<p style="margin: 0"> I am <span style="color: yellow">yellow</span>.</p>
<p style="margin: 0"> I am <span style="color: green">green</span>.</p>
<p style="margin: 0"> I am <span style="color: blue">blue</span>.</p>
<p style="margin: 0"> I am <span style="color: purple">purple</span>.</p>
'''
,dangerously_allow_html=True)
)
if __name__ == '__main__':
app.run_server(debug=True)
Also faced an issue that using <span style="color: red">Hey you</span> doesn’t render a tag for me. Found a solution here.
Quick answer: surrounding your text block with <p> tag solves the issue, but disallows using any markdown formatting like **bold** or _italic_.
Alternative is to use <span style="color: red" children="Hey you" /> at any place - this doesn’t break other formatting.