From 83de4ec69681ba0a38414eab12e1c7c73bdfb86b Mon Sep 17 00:00:00 2001 From: Tarek Allam Date: Thu, 14 May 2020 12:13:51 +0100 Subject: [PATCH 1/3] Encompass {id} field double quotes, remove \n char modified: _html.py --- packages/python/plotly/plotly/io/_html.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/python/plotly/plotly/io/_html.py b/packages/python/plotly/plotly/io/_html.py index f2f4aba0ef1..82414d170cb 100644 --- a/packages/python/plotly/plotly/io/_html.py +++ b/packages/python/plotly/plotly/io/_html.py @@ -230,14 +230,14 @@ def to_html( # Serialize config dict to JSON jconfig = json.dumps(config) - script = """ - if (document.getElementById("{id}")) {{ - Plotly.newPlot( - '{id}', - {data}, - {layout}, - {config} - ){then_addframes}{then_animate}{then_post_script} + script = """\ + if (document.getElementById("{id}")) {{\ + Plotly.newPlot(\ + "{id}",\ + {data},\ + {layout},\ + {config}\ + ){then_addframes}{then_animate}{then_post_script}\ }}""".format( id=plotdivid, data=jdata, From 787bdb8654c8f530debd386a6ea1bd6bbad84a62 Mon Sep 17 00:00:00 2001 From: Tarek Allam Date: Thu, 14 May 2020 12:16:24 +0100 Subject: [PATCH 2/3] Ensure '\n' char is removed using '\' at EOL modified: _html.py --- packages/python/plotly/plotly/io/_html.py | 25 +++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/python/plotly/plotly/io/_html.py b/packages/python/plotly/plotly/io/_html.py index 82414d170cb..7781765594d 100644 --- a/packages/python/plotly/plotly/io/_html.py +++ b/packages/python/plotly/plotly/io/_html.py @@ -333,25 +333,24 @@ def to_html( Invalid value of type {typ} received as the include_mathjax argument Received value: {val} -include_mathjax may be specified as False, 'cdn', or a string ending with '.js' +include_mathjax may be specified as False, 'cdn', or a string ending with '.js' """.format( typ=type(include_mathjax), val=repr(include_mathjax) ) ) plotly_html_div = """\ -
- {mathjax_script} - {load_plotlyjs} -
- -
""".format( +
\ + {mathjax_script}\ + {load_plotlyjs}\ +
\ +
\ + \ +
\ + """.format( mathjax_script=mathjax_script, load_plotlyjs=load_plotlyjs, id=plotdivid, From 0f99249ac15aa472fdbd57c6c7b2b74be807699b Mon Sep 17 00:00:00 2001 From: Tarek Allam Date: Thu, 14 May 2020 12:17:10 +0100 Subject: [PATCH 3/3] Remove leading and trailing whitespace of string Example without .strip(): '
... Example with .strip()': '
... modified: _html.py --- packages/python/plotly/plotly/io/_html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/io/_html.py b/packages/python/plotly/plotly/io/_html.py index 7781765594d..72015d107bd 100644 --- a/packages/python/plotly/plotly/io/_html.py +++ b/packages/python/plotly/plotly/io/_html.py @@ -360,7 +360,7 @@ def to_html( require_start=require_start, script=script, require_end=require_end, - ) + ).strip() if full_html: return """\