Skip to content

Commit cace50d

Browse files
authored
Merge pull request #1820 from plotly/fixup-html-entity-number
Fixup html entity number
2 parents a1b4dd2 + 45bd22a commit cace50d

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/constants/string_mappings.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,32 @@
1010
'use strict';
1111

1212
// N.B. HTML entities are listed without the leading '&' and trailing ';'
13+
// https://www.freeformatter.com/html-entities.html
1314

1415
module.exports = {
15-
1616
entityToUnicode: {
1717
'mu': 'μ',
18+
'#956': 'μ',
19+
1820
'amp': '&',
21+
'#28': '&',
22+
1923
'lt': '<',
24+
'#60': '<',
25+
2026
'gt': '>',
27+
'#62': '>',
28+
2129
'nbsp': ' ',
30+
'#160': ' ',
31+
2232
'times': '×',
33+
'#215': '×',
34+
2335
'plusmn': '±',
24-
'deg': '°'
25-
},
26-
27-
unicodeToEntity: {
28-
'&': 'amp',
29-
'<': 'lt',
30-
'>': 'gt',
31-
'"': 'quot',
32-
'\'': '#x27',
33-
'\/': '#x2F'
34-
}
36+
'#177': '±',
3537

38+
'deg': '°',
39+
'#176': '°'
40+
}
3641
};

test/jasmine/tests/svg_text_utils_test.js

+9
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ describe('svg+text utils', function() {
262262
expect(node.text()).toEqual('100μ & < 10 > 0  100 × 20 ± 0.5 °');
263263
});
264264

265+
it('decodes some HTML entities in text (number case)', function() {
266+
var node = mockTextSVGElement(
267+
'100&#956; &#28; &#60; 10 &#62; 0 &#160;' +
268+
'100 &#215; 20 &#177; 0.5 &#176;'
269+
);
270+
271+
expect(node.text()).toEqual('100μ & < 10 > 0  100 × 20 ± 0.5 °');
272+
});
273+
265274
it('supports superscript by itself', function() {
266275
var node = mockTextSVGElement('<sup>123</sup>');
267276
expect(node.html()).toBe(

0 commit comments

Comments
 (0)