-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
text annotations with with hrefs containing encoded characters such as '#' break links #4084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks very much for reporting! |
related: #3449 |
Some interesting thoughts in #2239 (comment) |
Hello! |
You can hijack pio._html._window_plotly_config += """
<script>
_encodeURI = encodeURI;
encodeURI = uri => _encodeURI(uri)
.replace('%2523', '%23') // #
.replace('%253A', '%3A'); // :
</script>
""" |
Thanks for the hack! import plotly.graph_objects as go
import plotly.io as pio
from plotly.io import _html
from plotly.offline import init_notebook_mode, iplot, download_plotlyjs
_html._window_plotly_config += """
<script>
_encodeURI = encodeURI;
encodeURI = uri => _encodeURI(uri)
.replace('%252b', '%2b') // #
</script>
"""
text = "<a href='http://simbad.u-strasbg.fr/simbad/sim-id?Ident=SDSS+J000102.74%2b012941.9'>Link</a>"
print(text)
data=go.Scatter(x=[1],y=[1],mode='markers+text',
hovertext = text,
text=[text])
fig=go.Figure([data])
iplot(fig) You can see that the link I prink works: http://simbad.u-strasbg.fr/simbad/sim-id?Ident=SDSS+J000102.74%2b012941.9 Thanks for you help! |
Your example works fine for me. Which version of plotly are you on? |
5.5.0. |
Yes, it should work in your terminal too. For JupyterLab (on Binder), you can run: from IPython.display import display, Javascript
display(Javascript("""
window._encodeURI = window._encodeURI || encodeURI;
encodeURI = uri => _encodeURI(uri)
.replace('%2523', '%23') // #
.replace('%253A', '%3A') // :
.replace('%252b', '%2b'); // +
""")) |
Thanks a lot for your help!!!! |
I've run into this issue in a JS application where the URIs I'd like to link to may contain escaped characters, including My ideal solution would be to add a config parameter to disable Plotly's broken URI sanitization for a single plot. Then I can do my own sanitization elsewhere. |
The solution that was adopted in #2471 to enable support for encoded hrefs seems to break for characters like
#
and:
. This seems to be because JavaScript'sencodeURI
anddecodeURI
do not encode/decode these characters. Perhaps more nuanced used ofencodeURIComponent
anddecodeURIComponent
needs to be used?Here's a minimal working example in Python, which is trying to link to a Twitter query for
#food lang:en
, in which the#
and:
characters need to be encoded:The generated link ends up being scrambled because the hash and colon escape sequences are not decoded, but are then encoded again, resulting in the following Twitter search:
%23food lang%3Aen
The text was updated successfully, but these errors were encountered: