Skip to content

Fixup html entity number #1820

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

Merged
merged 2 commits into from
Jun 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/constants/string_mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,32 @@
'use strict';

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

module.exports = {

entityToUnicode: {
'mu': 'μ',
'#956': 'μ',

'amp': '&',
'#28': '&',

'lt': '<',
'#60': '<',

'gt': '>',
'#62': '>',

'nbsp': ' ',
'#160': ' ',

'times': '×',
'#215': '×',

'plusmn': '±',
'deg': '°'
},

unicodeToEntity: {
'&': 'amp',
'<': 'lt',
'>': 'gt',
'"': 'quot',
'\'': '#x27',
'\/': '#x2F'
}
'#177': '±',

'deg': '°',
'#176': '°'
}
};
9 changes: 9 additions & 0 deletions test/jasmine/tests/svg_text_utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ describe('svg+text utils', function() {
expect(node.text()).toEqual('100μ & < 10 > 0  100 × 20 ± 0.5 °');
});

it('decodes some HTML entities in text (number case)', function() {
var node = mockTextSVGElement(
'100&#956; &#28; &#60; 10 &#62; 0 &#160;' +
'100 &#215; 20 &#177; 0.5 &#176;'
);

expect(node.text()).toEqual('100μ & < 10 > 0  100 × 20 ± 0.5 °');
});

it('supports superscript by itself', function() {
var node = mockTextSVGElement('<sup>123</sup>');
expect(node.html()).toBe(
Expand Down