Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

Commit 887beb0

Browse files
committed
decode HTML entity numbers corresponding set of supported codes
1 parent 09181b1 commit 887beb0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/constants/string_mappings.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,30 @@
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': '°'
36+
'#177': '±',
2537
},
2638

2739
unicodeToEntity: {
@@ -33,4 +45,6 @@ module.exports = {
3345
'\/': '#x2F'
3446
}
3547

48+
'deg': '°',
49+
'#176': '°'
3650
};

test/jasmine/tests/svg_text_utils_test.js

Lines changed: 9 additions & 0 deletions
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)