From 1234e4f452c763188a4b37aaae04181df5d328cd Mon Sep 17 00:00:00 2001 From: Jonathan Olson Date: Thu, 8 Dec 2022 12:15:08 -0700 Subject: [PATCH] Wrap chemical formulas in LTR marks, see https://github.com/phetsims/chipper/issues/1355 --- js/util/StringUtils.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/js/util/StringUtils.js b/js/util/StringUtils.js index fda4d060..1b013a4a 100644 --- a/js/util/StringUtils.js +++ b/js/util/StringUtils.js @@ -283,6 +283,28 @@ var StringUtils = { return string.replace( /\u202a/g, '[LTR]' ).replace( /\u202b/g, '[RTL]' ).replace( /\u202c/g, '[POP]' ); }, + /** + * Wraps a string with embedding marks for LTR display. + * @public + * + * @param {string} string + * @returns {string} + */ + wrapLTR: function( string ) { + return LTR + string + POP; + }, + + /** + * Wraps a string with embedding marks for RTL display. + * @public + * + * @param {string} string + * @returns {string} + */ + wrapRTL: function( string ) { + return LTR + string + POP; + }, + /** * Assert that a template var is in a string. Useful for translated strings with a template var pattern like * "Hello {{meanName}}" --> "Hello goofball". See StringUtils.fillIn() for base usages of template var pattern.