-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Tooltip Template string switch from single quotes to template literal. #955
Conversation
…gle quotes which were interupted with other possessive single quotes. Switching these to template literals should address the issue. I noticed this with the following string concatenation example from a dataset: ``'<div>' + 'City: Saint John's<br>Country: Antigua and Barbuda<br>Continent: North America' + '</div>'`
@@ -361,8 +361,8 @@ class Tooltip(MacroElement): | |||
_template = Template(u""" | |||
{% macro script(this, kwargs) %} | |||
{{ this._parent.get_name() }}.bindTooltip( | |||
'<div{% if this.style %} style="{{ this.style }}"{% endif %}>' | |||
+ '{{ this.text }}' + '</div>', | |||
`<div{% if this.style %} style="{{ this.style }}"{% endif %}>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I did not know about template literal
. I guess there are more places in folium
where that would be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are good with ES6 syntax right? The template literals
in JS are pretty useful - the equivalent of Python 3.6 f-strings and are nice for embedding different types into a string.
I'll prepare a bugfix release tomorrow. Thanks for the fix! |
Here is a page on browser compatibility: Chrome is since 41, which is from May 2015. Firefox sinds 34 from December 2014. Edge supported it since the start. Internet Explorer doesn't support template literals though. Maybe there were other incompatibilities with legacy browsers in folium already, but if not we may leave some users behind with this. But I guess there's no excuse for using an outdated browser nowadays. |
I've been playing around with this and this is great stuff! Using this in Apart from |
Good to know. Thanks for looking into it @Conengmo! |
@Conengmo awesome! one question - does this negate the need for |
I don't think so. A possible use case if you want to show literal html in your text. (But who would want that? :p) Also, special characters seem to work for me, but there may be cases where you want them converted to html entities. |
I think some of the source of the confusion has to do with the naming of the keyword argument. When I read I think it would be more clear to end users what it does if it was named something like I'm personally fine with it either way as I don't need it a lot - but I think it might be more clear to people that could need to use it. |
I like
That was default but it caused other issues so we reverted it. |
I noticed a bug in the template due to concatenating strings with single quotes which were interrupted with other possessive single quotes. Switching these to template literals should address the issue.
I noticed this with the following string concatenation example from a dataset:
'<div>' + 'City: Saint John's<br>Country: Antigua and Barbuda<br>Continent: North America' + '</div>'