Skip to content

Commit a943db2

Browse files
committed
fold string_mappings into svg_text_utils
1 parent 67156b2 commit a943db2

File tree

2 files changed

+26
-33
lines changed

2 files changed

+26
-33
lines changed

src/constants/string_mappings.js

-32
This file was deleted.

src/lib/svg_text_utils.js

+26-1
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)