Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a943db2

Browse filesBrowse files
committed
fold string_mappings into svg_text_utils
1 parent 67156b2 commit a943db2
Copy full SHA for a943db2

File tree

2 files changed

+26
-33
lines changed
Filter options

2 files changed

+26
-33
lines changed

‎src/constants/string_mappings.js

Copy file name to clipboardExpand all lines: src/constants/string_mappings.js
-32Lines changed: 0 additions & 32 deletions
This file was deleted.

‎src/lib/svg_text_utils.js

Copy file name to clipboardExpand all lines: src/lib/svg_text_utils.js
+26-1Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var d3 = require('d3');
1515

1616
var Lib = require('../lib');
1717
var xmlnsNamespaces = require('../constants/xmlns_namespaces');
18-
var entityToUnicode = require('../constants/string_mappings').entityToUnicode;
1918
var LINE_SPACING = require('../constants/alignment').LINE_SPACING;
2019

2120
// text converter
@@ -278,6 +277,32 @@ exports.plainText = function(_str) {
278277
return (_str || '').replace(STRIP_TAGS, ' ');
279278
};
280279

280+
/*
281+
* N.B. HTML entities are listed without the leading '&' and trailing ';'
282+
* https://www.freeformatter.com/html-entities.html
283+
*
284+
* FWIW if we wanted to support the full set, it has 2261 entries:
285+
* https://www.w3.org/TR/html5/entities.json
286+
* though I notice that some of these are duplicates and/or are missing ";"
287+
* eg: "&", "&amp", "&", and "&AMP" all map to "&"
288+
* We no longer need to include numeric entities here, these are now handled
289+
* by String.fromCodePoint/fromCharCode
290+
*
291+
* Anyway the only ones that are really important to allow are the HTML special
292+
* chars <, >, and &, because these ones can trigger special processing if not
293+
* replaced by the corresponding entity.
294+
*/
295+
var entityToUnicode = {
296+
mu: 'μ',
297+
amp: '&',
298+
lt: '<',
299+
gt: '>',
300+
nbsp: ' ',
301+
times: '×',
302+
plusmn: '±',
303+
deg: '°'
304+
};
305+
281306
// NOTE: in general entities can contain uppercase too (so [a-zA-Z]) but all the
282307
// ones we support use only lowercase. If we ever change that, update the regex.
283308
var ENTITY_MATCH = /&(#\d+|#x[\da-fA-F]+|[a-z]+);/g;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.