Raymond Hill 2018-07-30 08:56:51 -04:00
parent 756288294d
commit ec8e1cca15
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 21 additions and 10 deletions

View File

@ -79,16 +79,27 @@ var safeTextToTagNode = function(text) {
} }
}; };
var safeTextToTextNode = function(text) { var safeTextToTextNode = (function() {
// TODO: remove once no more HTML entities in translation files. let entities = new Map([
if ( text.indexOf('&') !== -1 ) { // TODO: Remove quote entities once no longer present in translation
text = text.replace(/“/g, '“') // files. Other entities must stay.
.replace(/”/g, '”') [ '“', '“' ],
.replace(/‘/g, '') [ '”', '”' ],
.replace(/’/g, ''); [ '‘', '' ],
} [ '’', '' ],
return document.createTextNode(text); [ '&lt;', '<' ],
}; [ '&gt;', '>' ],
]);
let decodeEntities = match => {
return entities.get(match) || match;
};
return function(text) {
if ( text.indexOf('&') !== -1 ) {
text = text.replace(/&[a-z]+;/g, decodeEntities);
}
return document.createTextNode(text);
};
})();
var safeTextToDOM = function(text, parent) { var safeTextToDOM = function(text, parent) {
if ( text === '' ) { return; } if ( text === '' ) { return; }