Skip to content

Commit e8b862b

Browse files
authored
Refine div formatting with to_html() + full_html=False (#2469)
Remove newlines and double quote strings for better Markdown compatibility
1 parent f5bff69 commit e8b862b

File tree

1 file changed

+21
-22
lines changed
  • packages/python/plotly/plotly/io

1 file changed

+21
-22
lines changed

Diff for: packages/python/plotly/plotly/io/_html.py

+21-22
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,14 @@ def to_html(
230230
# Serialize config dict to JSON
231231
jconfig = json.dumps(config)
232232

233-
script = """
234-
if (document.getElementById("{id}")) {{
235-
Plotly.newPlot(
236-
'{id}',
237-
{data},
238-
{layout},
239-
{config}
240-
){then_addframes}{then_animate}{then_post_script}
233+
script = """\
234+
if (document.getElementById("{id}")) {{\
235+
Plotly.newPlot(\
236+
"{id}",\
237+
{data},\
238+
{layout},\
239+
{config}\
240+
){then_addframes}{then_animate}{then_post_script}\
241241
}}""".format(
242242
id=plotdivid,
243243
data=jdata,
@@ -333,25 +333,24 @@ def to_html(
333333
Invalid value of type {typ} received as the include_mathjax argument
334334
Received value: {val}
335335
336-
include_mathjax may be specified as False, 'cdn', or a string ending with '.js'
336+
include_mathjax may be specified as False, 'cdn', or a string ending with '.js'
337337
""".format(
338338
typ=type(include_mathjax), val=repr(include_mathjax)
339339
)
340340
)
341341

342342
plotly_html_div = """\
343-
<div>
344-
{mathjax_script}
345-
{load_plotlyjs}
346-
<div id="{id}" class="plotly-graph-div" \
347-
style="height:{height}; width:{width};"></div>
348-
<script type="text/javascript">
349-
{require_start}
350-
window.PLOTLYENV=window.PLOTLYENV || {{}};{base_url_line}
351-
{script};
352-
{require_end}
353-
</script>
354-
</div>""".format(
343+
<div>\
344+
{mathjax_script}\
345+
{load_plotlyjs}\
346+
<div id="{id}" class="plotly-graph-div" \
347+
style="height:{height}; width:{width};">\
348+
</div>\
349+
<script type="text/javascript">\
350+
{require_start}window.PLOTLYENV=window.PLOTLYENV || {{}};{base_url_line}{script};{require_end}\
351+
</script>\
352+
</div>\
353+
""".format(
355354
mathjax_script=mathjax_script,
356355
load_plotlyjs=load_plotlyjs,
357356
id=plotdivid,
@@ -361,7 +360,7 @@ def to_html(
361360
require_start=require_start,
362361
script=script,
363362
require_end=require_end,
364-
)
363+
).strip()
365364

366365
if full_html:
367366
return """\

0 commit comments

Comments
 (0)