-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
improve pseudo-html entity conversion #2932
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
Conversation
- move it later in the convertToTspans pipeline - support all numbered entities (including the correct ampersand code!)
}); | ||
|
||
it('decodes some HTML entities in text (number case)', function() { | ||
var node = mockTextSVGElement( | ||
'100μ  < 10 > 0  ' + | ||
'100μ & < 10 > 0  ' + |
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.
No, the ampersand is not 
...
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.
Oops. My bad.
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.
oh haha I assumed I did that 🙈
var stringFromCodePoint = String.fromCodePoint; | ||
if(stringFromCodePoint) return stringFromCodePoint(code); | ||
|
||
// IE doesn't have String.fromCodePoint |
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.
To be fair, not just IE doesn't support fromCodePoint
, 2015 Chrome and 2014 FF didn't have it either.
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.
Fair enough - though we don't support such old versions of Chrome and FF, do we?
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.
do we?
We used to have a blob on https://plot.ly/javascript/ (that I can't find right now) saying plotly.js is supported in all SVG-enabled browsers. But yeah, the fraction of users still using Chrome41 and FF29 must be tiny.
@@ -10,7 +10,7 @@ | |||
'use strict'; | |||
|
|||
var toSuperScript = require('superscript-text'); | |||
var stringMappings = require('../constants/string_mappings'); | |||
var fixEntities = require('./svg_text_utils').convertEntities; |
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.
Very nice here.
Now string_mapping
is only required in svg_text_utils.js
. Would you mind moving the entityToUnicode
lookup table to svg_text_utils.js
and 🔪 string_mapping.js
?
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.
good call -> 🔪 string_mapping.js
in a943db2
var outChar; | ||
if(innerMatch.charAt(0) === '#') { | ||
// cannot use String.fromCodePoint in IE | ||
outChar = fromCodePoint( |
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.
Support all numbered entities, decimal and hex - including the correct ampersand code!
Brilliant ✨
Very nice PR. 🥇 I tried to find a case where the new I'll give you a 💃 , but I wouldn't mind waiting a few days before merging it in case we need to patch Now about,
If someone really wants us to decode all named html entities, I suggest we make an optional component (similar to calendars) that would require some third-party module (e.g. |
<
as<
and make a tag out of itfixEntities
function there, which was overly aggressive about finding entities, I just pointed it to the SVG version. It's possible that the simple loop-based function there would be faster, but making it work correctly would have slowed it down and made it more complicated, and anyway the other transformations inhtml2unicode
use regex replacements so I guess this wasn't hyper-optimized anyway.cc @etpinard